See the following source code:
<%
'Write data to the database
Sub writedata ()
Dim reccnt, I
Dim fieldname1, fieldname2, fieldname3
Dim Conn
Dim sqlstr, connstr
Connstr = "provider = sqloledb.1; initial catalog = mydatabase; Data Source = myhon; user id = sa; Password ="
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open connstr 'create a database connection
Reccnt = request. Form ("stu_num"). count' gets the total number of records
'Batch Data Entry
For I = 1 to reccnt
Fieldname1 = trim (request. Form ("fieldname1") (I ))
Fieldname2 = trim (request. Form ("fieldname2") (I ))
Fieldname3 = trim (request. Form ("fieldname3") (I ))
Sqlstr = "insert into mytable (fieldname1, fieldname2, fieldname3) values ('"
Sqlstr = sqlstr & fieldname1 &"','"
Sqlstr = sqlstr & fieldname2 &"','"
Sqlstr = sqlstr & fieldname3 &"')"
'Response. Write sqlstr
Conn.exe cute (sqlstr)
Next
End sub
'Display the batch entry interface
Sub inputdata ()
Dim reccnt, I
%>
<Form name = "bathinputdata" Action = "" method = "Post">
<%
Reccnt = CINT (request. Form ("reccnt "))
For I = 1 to reccnt
%>
<Input type = "text" name = "fieldname1">
<Input type = "text" name = "fieldname2">
<Input type = "text" name = "fieldname3">
<%
Next
%>
<Br>
<Input type = "Submit" name = "action" value = "Submit">
</Form>
<%
End sub
'Specifies the number of records to be entered in batches.
Sub assignhowmuch ()
%>
<! ------ Specify the number of records to be entered ------------>
<Form name = "form1" Action = "" method = "Post">
Number of records you want to enter: <input type = "text" name = "reccnt">
<Input type = "Submit" name = "action" value = "next>">
</Form>
<%
End sub
If request. Form ("action") = "next>" then
Call inputdata () 'displays the batch Input Interface
Elseif request. Form ("action") = "Submit" then call writedata () 'to batch write data to the database
Else
Call assignhowmuch () 'displays the interface for specifying the number of records to be entered
End if
%>