Realization of _asp in batch input data based on ASP

Source: Internet
Author: User
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 a 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
%>

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.