SoFunction
Updated on 2025-03-02

Asp implements the implementation of batch data entry

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.

The following is the specific code:
 
<% 
'##################################### 
'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=("") 
connStr 'Create a database connection
recCnt=("stu_num").count 'How many records are there in total?
'Batch input data
for i=1 to recCnt 
fieldName1=trim(("fieldName1")(i)) 
fieldName2=trim(("fieldName2")(i)) 
fieldName3=trim(("fieldName3")(i)) 
sqlStr="insert into myTable(fieldName1,fieldName2,fieldName3) values('" 
sqlStr=sqlStr & fieldName1 & "','" 
sqlStr=sqlStr & fieldName2 & "','" 
sqlStr=sqlStr & fieldName3 & "')" 
' sqlStr 
(sqlStr) 
next 
END SUB 
'Show batch input interface
SUB InputData() 
dim recCnt,i 
%> 
<form name="bathInputData" action="" method="post"> 
<%  
recCnt=cint(("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 
'Specify how many records to be entered in batches
SUB assignHowMuch() 
%> 
<!------Specify how many records to enter-------------------------->
<form name="form1" action="" method="post"> 
The number of records you want to enter: <input type="text" name="recCnt">
<input type="submit" name="action" value="Next>>">
</form> 
<% 
END SUB 
if ("action")="Next>>" then
Call InputData() 'Show batch entry interface
elseif ("action")="Submit" then Call writeData() 'Write data in batches to the database
else 
Call assignHowMuch() 'Show the interface to specify how many records to enter
end if 
%>