p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Professional (http://p2p.wrox.com/forumdisplay.php?f=63)
-   -   INSERT Multiple rows to database (http://p2p.wrox.com/showthread.php?t=56433)

melkin April 9th, 2007 03:02 PM

INSERT Multiple rows to database
 
Hi All.

I am using .asp classic NOT .NET!

I have a database called "oddlistorders" that users add to it when they shop around and select certain products. Once done, they can view thier cart which is the "oddlistorders" database.

I then need to take all that they ordered which each row has a unique user ID and customer code and pass it to another database called "oddlistprocessed".

They problem is, it works fine if thwy only order ONE item (one row of data), but if they order more than one item, I cant inssert more than one row at a time.

Here is what I use now which works perfectly for ONE item:
<%
Dim quantity
quantity = Request.Form("quantity")

sql= "Update oddlist Set quantity='"& quantity & "' WHERE user_ID=" & ID

Rs.Open sql, Conn
Conn.Close
Set Rs=Nothing
Set Conn = Nothing

%>

Thanks!!

dparsons April 9th, 2007 03:19 PM

cross post
http://p2p.wrox.com/topic.asp?TOPIC_ID=58829

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========

jonsey April 10th, 2007 08:53 AM

I normally use Class but it think this may help or at less give you some option I have used the With method to right multi rows to DB

Code:

            <%
Dim quantity
quantity = Request.Form("quantity")

sql= "Update oddlist Set quantity='"& quantity & "' WHERE user_ID=" & ID

Rs.Open sql, Conn

With Rs
.AddNew()
                    .Fields("DBField1") = Request.Form("FormData1")
                    .Fields("DBField2") = Request.Form("FormData2")
                    .Fields("DBField3") = Request.Form("FormData3")
                    .Fields("DBField4") = Request.Form("FormData4")

                .Update()
End With

Conn.Close
Set Rs=Nothing
Set Conn = Nothing

%>



melkin April 10th, 2007 09:03 AM

Thanks "Jonsey". But I wont now how many fields are being updated. One session can be 1 row, thext session can be 12 rows. So then how do i number the .AddNew()?

does this make sense?
The data is coming from a shopping cart, so we dont know how many rows for each customer to pass



All times are GMT -4. The time now is 10:25 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.