下面的例子演示了如何向access数据库中批量添加1000条内容重复的新闻项。初始数据库使用Ok3w 6.0动态版+静态版(http://www.ok3w.net/)中提供的access数据库。附件中包含了程序完整的代码和数据库文件。
<%
Dim Conn
Dim Rs
Dim sql
' Create an ADO connection and recordset object
Set Conn = Server.CreateObject( " ADODB.Connection ")
Set Rs = Server.CreateObject( " ADODB.Recordset ")
Conn.Open " DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= " & Server.MapPath( " data.mdb ")
sql= " SELECT ID, ChannelID,ClassID,SortPath,Title,Content FROM Ok3w_Article; "
' Set the lock and cursor type
Rs.CursorType = 2
Rs.LockType = 3
Rs.Open sql, Conn ' Open the recordset with sql query
For i = 1 To 1000
Rs.AddNew ' Prepare the database to add a new record and add
Rs( " ID ") = 9 + i
Rs( " ChannelID ") = 1
Rs( " ClassID ") = 2
Rs( " SortPath ") = " 0,1,2, "
Rs( " Title ") = " test title "
Rs( " Content ") = " test content "
Rs.Update ' Save the update
Next
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>
Dim Conn
Dim Rs
Dim sql
' Create an ADO connection and recordset object
Set Conn = Server.CreateObject( " ADODB.Connection ")
Set Rs = Server.CreateObject( " ADODB.Recordset ")
Conn.Open " DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= " & Server.MapPath( " data.mdb ")
sql= " SELECT ID, ChannelID,ClassID,SortPath,Title,Content FROM Ok3w_Article; "
' Set the lock and cursor type
Rs.CursorType = 2
Rs.LockType = 3
Rs.Open sql, Conn ' Open the recordset with sql query
For i = 1 To 1000
Rs.AddNew ' Prepare the database to add a new record and add
Rs( " ID ") = 9 + i
Rs( " ChannelID ") = 1
Rs( " ClassID ") = 2
Rs( " SortPath ") = " 0,1,2, "
Rs( " Title ") = " test title "
Rs( " Content ") = " test content "
Rs.Update ' Save the update
Next
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>
参考文章:
1、codefix:
http://www.codefixer.com/asp/