473,465 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

insert multiple records

I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to variables. I
need to take that entire recordset and insert it into another table on a
remote server. The below code only inserts 1 record. How do I change the
code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>
Jul 19 '05 #1
10 3195
Run multiple INSERT INTO statements.

or .... use a disconnected recordset, manipulate it by adding records and
setting the field values and then pass it back using BatchUpdate to get the
updates back to the database [which is how I would do it].

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:u3****************@TK2MSFTNGP10.phx.gbl...
I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to variables. I
need to take that entire recordset and insert it into another table on a
remote server. The below code only inserts 1 record. How do I change the
code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>

Jul 19 '05 #2
.... then again, I already have a custom DLL that I wrote some time ago that
gets me disconnected recordset for Access and SQL Server allowing me to
concentrate on the program as opposed to the ADO.

If you want it may be useful - not sure) then your welcome to it (VB
project and optional MSI installer):
http://ftp.belper.blue-canoe.net/RSAccess/

I have updated it for my own development to handle DBFs and also to allow
specification of the cursor location so that you can elect to get an active
server-side cursor recordset. If you need either of these then email me and
I'll update the ZIP and MSI.

Hope this helps.

Chris.

"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.

or .... use a disconnected recordset, manipulate it by adding records and
setting the field values and then pass it back using BatchUpdate to get the
updates back to the database [which is how I would do it].

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:u3****************@TK2MSFTNGP10.phx.gbl...
I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to variables. I
need to take that entire recordset and insert it into another table on a
remote server. The below code only inserts 1 record. How do I change the
code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>


Jul 19 '05 #3
>>Run multiple INSERT INTO statements.<<
do you have an example of this?
thanks
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.

or .... use a disconnected recordset, manipulate it by adding records and
setting the field values and then pass it back using BatchUpdate to get the updates back to the database [which is how I would do it].

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:u3****************@TK2MSFTNGP10.phx.gbl...
I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to variables. I
need to take that entire recordset and insert it into another table on a
remote server. The below code only inserts 1 record. How do I change the
code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>

Jul 19 '05 #4
You already have an example - just loop through the array or recordset of
values that you have to insert and run your current code for each one.

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:ev****************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.<<
do you have an example of this?
thanks
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl... Run multiple INSERT INTO statements.

or .... use a disconnected recordset, manipulate it by adding records and
setting the field values and then pass it back using BatchUpdate to get the updates back to the database [which is how I would do it].

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:u3****************@TK2MSFTNGP10.phx.gbl...
I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to variables. I
need to take that entire recordset and insert it into another table on a
remote server. The below code only inserts 1 record. How do I change the
code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>


Jul 19 '05 #5
I'm not that familiar with looping through recordsets. On the following
code, I get this error...

Expected end of statement
Dim i As Integer
------^
What do I need to change?
thanks
<%
Dim DataConn2
Dim i As Integer
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:em******************@tk2msftngp13.phx.gbl...
You already have an example - just loop through the array or recordset of
values that you have to insert and run your current code for each one.

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:ev****************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.<< do you have an example of this?
thanks
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.

or .... use a disconnected recordset, manipulate it by adding records

and setting the field values and then pass it back using BatchUpdate to get

the
updates back to the database [which is how I would do it].

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:u3****************@TK2MSFTNGP10.phx.gbl...
I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it into another table on a
remote server. The below code only inserts 1 record. How do I change the
code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>


Jul 19 '05 #6
Hmm.

OK.

1. You can't Dim *as* in ASP - everything is a variant.

So you now have:

<%
Dim DataConn2
Dim i
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "

'Where are the values for iod_OrderID etc. coming from?
'You need to set them here to be values relevant to the current index of
wsOrderDetails.

SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>

What is wsOrderDetails (I know that its obviously a table in your database)?

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:Za********************@twister.tampabay.rr.co m...
I'm not that familiar with looping through recordsets. On the following
code, I get this error...

Expected end of statement
Dim i As Integer
------^
What do I need to change?
thanks
<%
Dim DataConn2
Dim i As Integer
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:em******************@tk2msftngp13.phx.gbl...
You already have an example - just loop through the array or recordset of
values that you have to insert and run your current code for each one.

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:ev****************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.<< do you have an example of this?
thanks
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.

or .... use a disconnected recordset, manipulate it by adding records

and setting the field values and then pass it back using BatchUpdate to get

the
updates back to the database [which is how I would do it].

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:u3****************@TK2MSFTNGP10.phx.gbl...
I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it into another table on a
remote server. The below code only inserts 1 record. How do I change the
code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>



Jul 19 '05 #7
1) I changed wsOrderDetails to rsOrderDetails which is the recordset I am
getting records from. That was a typo on my part.

2) I am now getting the following error...
Expected end of statement
Next i
-----^
How do I fix that?
thanks!

<%
Dim DataConn2
Dim i
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To rsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:OS***************@tk2msftngp13.phx.gbl...
Hmm.

OK.

1. You can't Dim *as* in ASP - everything is a variant.

So you now have:

<%
Dim DataConn2
Dim i
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "

'Where are the values for iod_OrderID etc. coming from?
'You need to set them here to be values relevant to the current index of
wsOrderDetails.

SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>

What is wsOrderDetails (I know that its obviously a table in your database)?
Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:Za********************@twister.tampabay.rr.co m...
I'm not that familiar with looping through recordsets. On the following
code, I get this error...

Expected end of statement
Dim i As Integer
------^
What do I need to change?
thanks
<%
Dim DataConn2
Dim i As Integer
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:em******************@tk2msftngp13.phx.gbl...
You already have an example - just loop through the array or recordset of
values that you have to insert and run your current code for each one.

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:ev****************@TK2MSFTNGP10.phx.gbl...
>Run multiple INSERT INTO statements.<< do you have an example of this?
thanks
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.

or .... use a disconnected recordset, manipulate it by adding records and setting the field values and then pass it back using BatchUpdate to get the
updates back to the database [which is how I would do it].

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:u3****************@TK2MSFTNGP10.phx.gbl...
I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to
variables. I need to take that entire recordset and insert it into another table on

a remote server. The below code only inserts 1 record. How do I change the code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" & iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>



Jul 19 '05 #8
Try this:

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
'Presumes that rsOrderDetails is a recordset with 1 or more records that
contain order data.
With rsOrderDetails
If Not(.EOF) Then .MoveFirst
'Loop through the recordset and apply the data using an INSERT INTO sql
statement.
Do Until .EOF
'Get the relevant recordset field values.
iod_OrderID = .Fields("FieldName).Value
iod_OrderNo = .Fields("FieldName).Value
iod_Description = .Fields("FieldName).Value
iod_Qty = .Fields("FieldName).Value
iod_PriceEach = .Fields("FieldName).Value
iod_PriceLine = .Fields("FieldName).Value
'Construct the SQL
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description,
Qty, PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "',
'" & iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", &
iod_Priceline & ")"
'Execute the SQL
DataConn2.Execute(SQL)
.MoveNext
Loop
End With
%>

Obviously you have to change the fieldnames to be whatever they should be.

NB: Learn the value of indentation and comments when doing ASP - your
scripts will be spaghetti and unfathomable without it. Also, never ever
release a script or ASP page that doesn't use Option Explicit at the top -
you *will* regret it if you don't.

Hope this helps.

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:07********************@twister.tampabay.rr.co m...
1) I changed wsOrderDetails to rsOrderDetails which is the recordset I am
getting records from. That was a typo on my part.

2) I am now getting the following error...
Expected end of statement
Next i
-----^
How do I fix that?
thanks!

<%
Dim DataConn2
Dim i
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To rsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:OS***************@tk2msftngp13.phx.gbl...
Hmm.

OK.

1. You can't Dim *as* in ASP - everything is a variant.

So you now have:

<%
Dim DataConn2
Dim i
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "

'Where are the values for iod_OrderID etc. coming from?
'You need to set them here to be values relevant to the current index of
wsOrderDetails.

SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>

What is wsOrderDetails (I know that its obviously a table in your database)?
Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:Za********************@twister.tampabay.rr.co m...
I'm not that familiar with looping through recordsets. On the following
code, I get this error...

Expected end of statement
Dim i As Integer
------^
What do I need to change?
thanks
<%
Dim DataConn2
Dim i As Integer
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:em******************@tk2msftngp13.phx.gbl...
You already have an example - just loop through the array or recordset of
values that you have to insert and run your current code for each one.

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:ev****************@TK2MSFTNGP10.phx.gbl...
>Run multiple INSERT INTO statements.<< do you have an example of this?
thanks
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.

or .... use a disconnected recordset, manipulate it by adding records and setting the field values and then pass it back using BatchUpdate to get the
updates back to the database [which is how I would do it].

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:u3****************@TK2MSFTNGP10.phx.gbl...
I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to
variables. I need to take that entire recordset and insert it into another table on

a remote server. The below code only inserts 1 record. How do I change the code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" & iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>




Jul 19 '05 #9
Remove your "i".

Bob Lehmann

"shank" <sh***@tampabay.rr.com> wrote in message
news:07********************@twister.tampabay.rr.co m...
1) I changed wsOrderDetails to rsOrderDetails which is the recordset I am
getting records from. That was a typo on my part.

2) I am now getting the following error...
Expected end of statement
Next i
-----^
How do I fix that?
thanks!

<%
Dim DataConn2
Dim i
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To rsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:OS***************@tk2msftngp13.phx.gbl...
Hmm.

OK.

1. You can't Dim *as* in ASP - everything is a variant.

So you now have:

<%
Dim DataConn2
Dim i
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "

'Where are the values for iod_OrderID etc. coming from?
'You need to set them here to be values relevant to the current index of
wsOrderDetails.

SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>

What is wsOrderDetails (I know that its obviously a table in your database)?

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:Za********************@twister.tampabay.rr.co m...
I'm not that familiar with looping through recordsets. On the following
code, I get this error...

Expected end of statement
Dim i As Integer
------^
What do I need to change?
thanks
<%
Dim DataConn2
Dim i As Integer
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:em******************@tk2msftngp13.phx.gbl...
You already have an example - just loop through the array or recordset of values that you have to insert and run your current code for each one.
Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:ev****************@TK2MSFTNGP10.phx.gbl...
>>Run multiple INSERT INTO statements.<<
do you have an example of this?
thanks
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
> Run multiple INSERT INTO statements.
>
> or .... use a disconnected recordset, manipulate it by adding records
and
> setting the field values and then pass it back using BatchUpdate to get the
> updates back to the database [which is how I would do it].
>
> Chris.
>
> "shank" <sh***@tampabay.rr.com> wrote in message
> news:u3****************@TK2MSFTNGP10.phx.gbl...
> I have a recordset that contains multiple records of product a user
is > purchasing. For clarity, I converted the recordset fields to

variables.
I
> need to take that entire recordset and insert it into another table on a > remote server. The below code only inserts 1 record. How do I change the > code to get all records inserted?
> thanks!
>
> <%
> Dim DataConn2
> Set DataConn2 = Server.CreateObject("ADODB.Connection")
> DataConn2.Open MM_kasKSS_STRING
> SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description,
Qty, > PriceEach, Priceline) "
> SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "',
'" & > iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
> iod_Priceline & ")"
> DataConn2.Execute(SQL)
> %>
>
>
>



Jul 19 '05 #10
An watch out for my glaring type (copied and pasted):

... = .Fields("FieldName).Value

should be:

... = .Fields("FieldName").Value

with FieldName replaced by the real field name from rsOrderDetails.

Chris.

"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2*****************@TK2MSFTNGP09.phx.gbl...
Try this:

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
'Presumes that rsOrderDetails is a recordset with 1 or more records that
contain order data.
With rsOrderDetails
If Not(.EOF) Then .MoveFirst
'Loop through the recordset and apply the data using an INSERT INTO sql
statement.
Do Until .EOF
'Get the relevant recordset field values.
iod_OrderID = .Fields("FieldName).Value
iod_OrderNo = .Fields("FieldName).Value
iod_Description = .Fields("FieldName).Value
iod_Qty = .Fields("FieldName).Value
iod_PriceEach = .Fields("FieldName).Value
iod_PriceLine = .Fields("FieldName).Value
'Construct the SQL
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description,
Qty, PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "',
'" & iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", &
iod_Priceline & ")"
'Execute the SQL
DataConn2.Execute(SQL)
.MoveNext
Loop
End With
%>

Obviously you have to change the fieldnames to be whatever they should be.

NB: Learn the value of indentation and comments when doing ASP - your
scripts will be spaghetti and unfathomable without it. Also, never ever
release a script or ASP page that doesn't use Option Explicit at the top -
you *will* regret it if you don't.

Hope this helps.

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:07********************@twister.tampabay.rr.co m...
1) I changed wsOrderDetails to rsOrderDetails which is the recordset I am
getting records from. That was a typo on my part.

2) I am now getting the following error...
Expected end of statement
Next i
-----^
How do I fix that?
thanks!

<%
Dim DataConn2
Dim i
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To rsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:OS***************@tk2msftngp13.phx.gbl...
Hmm.

OK.

1. You can't Dim *as* in ASP - everything is a variant.

So you now have:

<%
Dim DataConn2
Dim i
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "

'Where are the values for iod_OrderID etc. coming from?
'You need to set them here to be values relevant to the current index of
wsOrderDetails.

SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>

What is wsOrderDetails (I know that its obviously a table in your database)?
Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:Za********************@twister.tampabay.rr.co m...
I'm not that familiar with looping through recordsets. On the following
code, I get this error...

Expected end of statement
Dim i As Integer
------^
What do I need to change?
thanks
<%
Dim DataConn2
Dim i As Integer
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
For i = 0 To wsOrderDetails.ListCount -1 Step 1
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" &
iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
Next i
DataConn2.Execute(SQL)
%>
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:em******************@tk2msftngp13.phx.gbl...
You already have an example - just loop through the array or recordset of
values that you have to insert and run your current code for each one.

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:ev****************@TK2MSFTNGP10.phx.gbl...
>Run multiple INSERT INTO statements.<< do you have an example of this?
thanks
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Run multiple INSERT INTO statements.

or .... use a disconnected recordset, manipulate it by adding records and setting the field values and then pass it back using BatchUpdate to get the
updates back to the database [which is how I would do it].

Chris.

"shank" <sh***@tampabay.rr.com> wrote in message
news:u3****************@TK2MSFTNGP10.phx.gbl...
I have a recordset that contains multiple records of product a user is
purchasing. For clarity, I converted the recordset fields to
variables. I need to take that entire recordset and insert it into another table on

a remote server. The below code only inserts 1 record. How do I change the code to get all records inserted?
thanks!

<%
Dim DataConn2
Set DataConn2 = Server.CreateObject("ADODB.Connection")
DataConn2.Open MM_kasKSS_STRING
SQL = "INSERT INTO wsOrderDetails (OrderID, OrderNo, Description, Qty,
PriceEach, Priceline) "
SQL = SQL & "Values ('" & iod_OrderID & "', '" & iod_OrderNo & "', '" & iod_Description & "', " & iod_Qty & ", " & iod_PriceEach & ", " &
iod_Priceline & ")"
DataConn2.Execute(SQL)
%>





Jul 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
2
by: Joe | last post by:
Hey, I'm going to give some background on my situation in case anyone can point out a way around my problem altogether... for the problem itself, please skip to the bottom of the post. thanks....
2
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. ...
0
by: jtocci | last post by:
I'm having a big problem with CREATE RULE...ON INSERT...INSERT INTO...SELECT...FROM...WHERE when I want to INSERT several (20~50) records based on a single INSERT to a view. Either I get a 'too...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
4
by: Mike Hnatt | last post by:
My goal is to get data from an XML file into a couple of tables in an Access database. The XML file is a little complex so I need control over what I do (I can't just read it into a dataset). ...
12
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
1
by: clayalphonso | last post by:
Here is the code: <% dim testArray, testArray2 dim Conn, rs dim sSQL, sConnString 'response.write request.form("sel1") 'testArray = split(request.form("sel1"),",") 'for each gidstuff In...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.