Batch entry is widely used in databases, and there are many methods for batch entry. Next, I will talk about how I achieved it based on my actual application. The main use is the concept of form collection, which takes all the data in the collection through loop. Considering that it is convenient for everyone to see, I integrated it into one page.
Here is the specific code:
batchInput.asp
<%
'#####################################################################
'FileFunction: Batch input data
'Author:Myhon
'Date:2003-8-19
'#####################################################################
'Write data to the database
SUBwriteData()
dimrecCnt,i
dimfieldName1, fieldName2, fieldName3
dimconn
dimsqlStr,connStr
connStr="Provider=SQLOLEDB.1;InitialCatalog=myDatabase;DataSource=myhon;UserId=sa;PASSWORD="
setconn=Server.CreateObject("ADODB.Connection")
conn.openconnStr' Establish database connection
recCnt=request.form("stu_num").count' How many records are there in total?
'Batch input data
fori=1torecCnt
fieldName1=trim(request.form("fieldName1")(i))
fieldName2=trim(request.form("fieldName2")(i))
fieldName3=trim(request.form("fieldName3")(i))
sqlStr="insertintomyTable(fieldName1,fieldName2,fieldName3)values('"
sqlStr=sqlStr&fieldName1&"','"
sqlStr=sqlStr&fieldName2&"','"
sqlStr=sqlStr&fieldName3&"')"
'response.writesqlStr
conn.execute(sqlStr)
next
ENDSUB
'Show batch input interface
SUBInputData()
dimrecCnt,i
%>
<formname="bathInputData" action=""method="post">
<%
recCnt=cint(request.form("recCnt"))
fori=1torecCnt
%>
<inputtype="text"name="fieldName1">
<inputtype="text"name="fieldName2">
<inputtype="text"name="fieldName3">
<%
next
%>
<br>
<inputtype="submit"name="action"value="submit">
</form>
<%
ENDSUB
'Specify how many records to be entered in batches
SUBassignHowMuch()
%>
<!------Specify how many records to enter------------------------->
<formname="form1"action=""method="post">
The number of records you want to enter: <inputtype="text"name="recCnt">
<inputtype="submit"name="action"value="Next>>">
</form>
<%
ENDSUB
ifrequest.form("action")="Next>>"then