Implement batch data entry using asp

Source: Internet
Author: User

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
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.