Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple insert record?

Status
Not open for further replies.

Cheech

Technical User
Nov 6, 2000
2,933
EU
I need to insert multiple records to a database depending on selected checkboxes anyoe seen this done & if so how????? I dont want to go to Chelsea!!!
 
Use multiple INSERT statements, executed one-by-one on your connection object.

sql = "INSERT INTO tableName (col1, col2) VALUES (val1, val2)

con.execute sql

repeat.

penny.gif
penny.gif
 
Cheers,

I was using passed variables from a form. Then needed to add a record for each checkbox ticked. Code below, not all my own work but adapted to my requirements and taken from many sources.

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<%
dim num
dim xide
dim sql
' create an array of checkbox vallues then loop through it
xide=split(request.querystring(&quot;checkbox&quot;),&quot;,&quot;,-1,1)
for each num in xide
' declaring variables
Dim DataConn
Dim CmdAddRecord
Dim MYSQL
' set connection
Set DataConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set CmdAddRecord = Server.CreateObject(&quot;ADODB.Recordset&quot;)
' Open the connection
DataConn.Open &quot;DSN=dsnMeetings&quot;
MYSQL = &quot;SELECT * FROM tbBookings&quot;
CmdAddRecord.Open MYSQL, DataConn, 1, 3
CmdAddRecord.AddNew
CmdAddRecord.Fields(&quot;site_id&quot;) = Request.Querystring(&quot;site&quot;)
CmdAddRecord.Fields(&quot;room_id&quot;) = Request.Querystring(&quot;room&quot;)
CmdAddRecord.Fields(&quot;book_date&quot;) = Request.Querystring(&quot;strDate&quot;)
CmdAddRecord.Fields(&quot;book_hour&quot;) = num
CmdAddRecord.Update
' closing objects and setting them to nothing
CmdAddRecord.Close
Set CmdAddRecord = Nothing
DataConn.Close
Set DataConn = Nothing
'Do the Loop
next
Response.Redirect &quot;anypage.asp&quot;
%>

I dont want to go to Chelsea!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top