Multiple "for each" statements

Results 1 to 10 of 10

Thread: Multiple "for each" statements

  1. #1
    Join Date
    Dec 1969
    Posts
    1,364

    Default Multiple "for each" statements

    I want to add data retrieved from a Form into an table<BR>And each entry in a new record with the "for each "statement<BR>One statement works but when i try the second statement the first gets lost.<BR>The code :<BR>for each Art in Request.Form("Art_aant") <BR>Next<BR>for each ID in Request.Form("Art_ID")<BR>SQL= "INSERT INTO Aantal(ART_AANTAL,ART_ID) Values (&#039" & Art & "" & ID & "&#039)"<BR>next<BR>Conn.execute sql<BR>%&#062;<BR>What am i overlooking...??<BR><BR>Much oblige

  2. #2
    Jairo Guest

    Default RE: Multiple

    Dan,<BR>Not sure if this is what you&#039re looking for but here goes:<BR><BR>&#060;%<BR>for each Art in Request.Form("Art_aant") <BR> for each ID in Request.Form("Art_ID")<BR> SQL= "INSERT INTO Aantal(ART_AANTAL,ART_ID) Values (&#039" & Art & "" & ID & "&#039)"<BR> Conn.execute sql<BR> Next<BR>next<BR>%&#062;<BR><BR>HTH,<BR>Jairo<BR>ht tp://www.citywebarchitects.com

  3. #3
    Join Date
    Dec 1969
    Posts
    1,364

    Default RE: Multiple ; Almost

    Now all the data is put in the Row "Art_aant" as well the data from ID as well from ART.<BR>I want data from ID to be put in the row Art_Id, and from ART into Art_aant.<BR><BR>So the data has to be put into two different rows.<BR>Again the code:<BR>&#060;%<BR>for each ID in Request.Form("Art_ID")<BR>for each ART in Request.Form("Art_aant")<BR>SQL= "INSERT INTO Aantal(ART_ID,ART_AANTAL) Values (&#039" & ID &" " & ART &"&#039)"<BR>Conn.execute sql<BR>Next<BR>Next<BR>%&#062;<BR><BR>

  4. #4
    Jairo Guest

    Default RE: Multiple ; Almost

    Dan,<BR>I&#039m still just a little bit confused. Correct me if I am misunderstanding. You want 1 record for each Art ID. I am assuming that the Art_ID and Art_aant are synchronized - i.e. if there are 10 Art IDs, then there are 10 Art_aants.<BR><BR>What is the structure of the data in Request.Form("ART_ID") as well as Request.Form("ART_AANT") ?<BR><BR>-Jairo<BR>http://www.citywebarchitects.com


  5. #5
    Join Date
    Dec 1969
    Posts
    1,364

    Default RE: Multiple ; Almost

    Yes Jairo,<BR><BR>If there are 10 ART_Aant than there are 10 ART_id.<BR>Art_aant is filled by an input form, ART_id is a unique Id for an article(retrieved from a hidden form field)<BR>The table is made to retrieve data to put in a query to create a kind of shoping cart.<BR>Hope i explained myself clear now.<BR><BR>Thanx already,

  6. #6
    John Weeflaar Guest

    Default RE: Multiple

    You can try this:<BR>for i = 1 To Request.Form("Art_aant").Count <BR>Art = Request.Form("Art_aant")<BR>ID = Request.Form("Art_ID")<BR>SQL= "INSERT INTO Aantal(ART_AANTAL,ART_ID)"<BR>SQL= SQL & " Values (&#039" & Art & "&#039, &#039" & ID & "&#039)"<BR>next<BR><BR>Hope that helps.

  7. #7
    John Weeflaar Guest

    Default RE: Multiple

    Oops, sorry, I forgot to include the "i":<BR>for i = 1 To Request.Form("Art_aant").Count <BR>Art = Request.Form("Art_aant")(i)<BR>ID = Request.Form("Art_ID")(i)<BR>SQL= "INSERT INTO Aantal(ART_AANTAL,ART_ID)"<BR>SQL= SQL & " Values (&#039" & Art & "&#039, &#039" & ID & "&#039)"<BR>next<BR>

  8. #8
    Join Date
    Dec 1969
    Posts
    1,364

    Default Doesn't work

    Nope doesn&#039t work.<BR>Maby another bright idea

  9. #9
    John Weeflaar Guest

    Default RE: Doesn't work

    I&#039ve been out of the net for a while. Ok, what I meant is this:<BR>for i = 1 To Request.Form("Art_aant").Count <BR>Art = Request.Form("Art_aant")(i)<BR>ID = Request.Form("Art_ID")(i)<BR>SQL= "INSERT INTO Aantal(ART_AANTAL,ART_ID)"<BR>SQL= SQL & " Values (&#039" & Art & "&#039, &#039" & ID & "&#039)"<BR>conn.Execute(SQL) &#039of course this should be present<BR>next<BR> <BR>I assume you have several input textboxes having the same names (Art_aant), yet having different values.<BR>Same assumption for the hidden fields (same names, different values). This should work.<BR>If this is not what you mean, please show your other form code to avoid people getting confused trying to understand your problem.<BR><BR>John<BR><BR>

  10. #10
    Join Date
    Dec 1969
    Posts
    1,364

    Default RE: Doesn't work

    John,<BR><BR> It works ....and the best thing is ..I understand what the code does and that is the most important.<BR><BR>Thanx for your ideas

Posting Permissions

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