multiple record insert into DB

Results 1 to 4 of 4

Thread: multiple record insert into DB

  1. #1
    Join Date
    Dec 1969
    Posts
    760

    Default multiple record insert into DB

    i have a form that inserts data into a table. The form is a registrant appication so that a user can put multiple entrants in. That way a db table only has 3 fields (registrantid, registrantname, registrantlocation). Exactly the same application as a shopping cart, except that my users aren&#039t selecting products, rather adding multiple names. <BR>Pretty easy, huh? My problem is I can&#039t figure out how to get the sql "insert into" to insert the multiple "shopping cart" rows into multiple rows in the DB. <BR>I guess the quick question is "how do you insert items into multiple rows in a db table?"<BR>I have be analyzing the code in the MicroSoft Adventure Works shopping cart sample that ships with ASP. Their "insert into" statement has "For i = 1 to iCount" before the sql statement.<BR>Is this the key. Any help or direction to get help is always appreciated. <BR>Thanks <BR>Andrew

  2. #2
    Richard L. Guest

    Default RE: multiple record insert into DB

    Let me understand what you want to do, you have a form that people submit multiple names from and you want to insert those names into a table? Or were there two tables involved?

  3. #3
    Join Date
    Dec 1969
    Posts
    760

    Default RE: multiple record insert into DB

    Richard- <BR>one table. here is the senario...<BR><BR>one file is entrants.htm, it posts to summary.asp.<BR>entrants.htm has four text fields : Your name, Your Location, Your Registrant, Your Registrant Type.<BR>Once the person puts his name in, then his location, he then enters his first person he wants to enroll. Then he submits the form to summary.asp. Summary.asp then produces a "cart" of entrants. He sees his name above the "cart" and below is a table showing the first row as his first entrant. He then can click "Enroll More" to go back to entrants.htm. He then puts another name in, clicks submit to summary.asp, as now sees in addition to his first entrant in the first row, a second row with his second entrant. <BR>After he has put as many entrants in the "cart" as he wants, he then clicks "submit" to add them to the DB. <BR>How do I get each entrant the user put in the "cart" as a new record rather than one long record with a whole bunch of fields (each field being a new entrant)?<BR>I hope that makes more sense, or if I confused it more, let me know..<BR>Thanks for responding<BR>Andrew

  4. #4
    Richard L. Guest

    Default RE: multiple record insert into DB

    If you&#039re not going to be having a lot of users updating in this way, I&#039d create a collection of arrays and put it in a session variable:<BR><BR>Dim myEntrants (99) &#039 AN ARRAY TO HOLD YOUR OTHER ARRAYS<BR><BR>&#039 IN THE REAL CODE JUST ONE ARRAY WITH 4 ELEMENTS WILL DO<BR>Dim myE1 (3) <BR>Dim myE2 (3)<BR><BR>YourName = 1<BR>myE1(0) = YourName<BR>myE1(1) = YourName &#039 SET ALL YOUR OTHER VARIABLES HERE<BR>myE1(2) = YourName<BR>myE1(3) = YourName<BR><BR>&#039 THIS WOULD BE THE 2ND TIME AROUND ON THE ENTRY PAGE<BR>myE2(0) = YourName <BR>myE2(1) = YourName<BR>myE2(2) = YourName<BR>myE2(3) = YourName<BR><BR>&#039 ADD THE ARRAYS INTO YOUR COLLECTION<BR>myEntrants(0) = myE1<BR>myEntrants(1) = myE2<BR><BR>&#039 ASSIGN YOUR COLLECTION OF ARRAYS TO A SESSION VAR.<BR>Session("entrants") = myEntrants<BR><BR>&#039 THIS IS HOW YOU DISPLAY ON THE &#039CART&#039 PAGE<BR>For each arrayObj in Session("entrants")<BR> for x = 0 to 3<BR> if isArray(arrayObj) Then<BR> response.write "<BR>" & arrayObj(x)<BR> end if<BR> Next<BR>Next<BR><BR>If this is unclear, let me know... I&#039ll help!<BR>Richard L.<BR>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •