Batch entry is widely used in databases, and there are many methods for batch entry. Next I will talk about how I implement it based on my actual application. We mainly use the form set concept to retrieve all the data in the set through a loop. For your convenience, I have integrated it into a page.
The specific code is as follows:
BatchInput. asp
<%
'#####################################
'File Function: Batch Data Input
'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 '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
%>