Batch input in the application of the database is more extensive, on the volume of the method also has many kinds of input.
Below I combine my practical application, talk about how I realize.
The main use is the concept of the set of form, by looping through all the data in the collection.
Considering everyone's convenience, I integrated it into a page.
The following are the specific code:
Batchinput.asp
<%
'#####################################
' File Function: Batch input data
' Author:myhon
' Date:2003-8-19
'#####################################
' 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 ' Establish a database connection
reccnt=request.form ("Stu_num") .count ' get total number of records
' batch input data
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.execute (sqlstr)
next
End SUB
' Display a batch input 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= "commit" >
</form>
<%
End SUB
' Specify how many records to be entered in batches
SUB Assignhowmuch ()
%>
<!------Specify how many records to input-------------->
<form name= "Form1" action= "" method= "POST" >
Number of records you want to input: <input type= "text" name= "reccnt" >
<input type= "Submit" name= "action" value= "next >>" >
</form>
<%
End SUB
If Request.Form ("action") = "Next >>" then
Call Inputdata () ' Show Batch Entry interface
ElseIf Request.Form ("action") = "Submit" then call WriteData () to bulk write data to the database
Else
Call Assignhowmuch () ' shows the interface of how many records are specified for entry
End If
%>