+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 23

Thread: For Next Loop Within another For Next Loop

  1. #11
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    That error message does not indicate a data type problem. Post your query.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  2. #12
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by Wolffy View Post
    That error message does not indicate a data type problem. Post your query.
    Code:
    sql="INSERT INTO [shows] (showName)"
    sql=sql & " VALUES "
    sql=sql & "('" & Request.Form("showName") & "')"
    
    'on error resume next
    conn.Execute sql,recaffected 
    
    response.write "the show inserted"
    
    
    'create a new recordset to hold the new data, as we need to run a separate query to find the showID
    
    set rs2 = Server.CreateObject("ADODB.recordset")
    sql2 = "SELECT @@Identity"
    set rs2 = conn.execute(sql2)
    bookingID = "Your Show Number is: " & rs2(0)
    showID = rs2(0)
    'response.write "<br>"
    'response.write "And so did the show: "
    'response.write rs2(0)
    
    
    For x = 1 To 10
    	SQL = "INSERT INTO [performances] (showID, SeatNumber, SeatPrice, performance_time, ShowDate, ShowStatus) " & _
    		"VALUES ( " & _
    		showID & ", " & _
    		x & ", " & _
    		Request.Form("SeatPrice") & ", " & _
    		Request.Form("performance_time") & ", " & _
    		Request.Form("ShowDate") & ", " & _
    		"'" & Request.Form("ShowStatus") & "')"
    	conn.Execute SQL
    	'response.write SQL
    Next
    
    idea is, insert the show, then query the showID and then run the loop

  3. #13
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    I meant the output from the response.write -- the code is useless in debugging this.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  4. #14
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by Wolffy View Post
    I meant the output from the response.write -- the code is useless in debugging this.
    wooofy, gonna have to reply back after ive done some further testing of my own.. will post up my findings later on or tommorow.

  5. #15
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    There is also a serious flaw in your logic, if this is a multi-user application. @@identity will return the last identity value inserted, regardless of session. If there is more than one user accesses the application, it is possible that an INSERT statement will be executed (and it doesn't matter what table it's on) between the time of your first INSERT and the query to return the @@identity -- the result being that you will get the WRONG VALUE for @@identity.

    If you must, do it this way (pseudo code):
    Code:
    Set timestamp = currentTime()
    Insert Into Shows
      (ShowName, DateCreated)
    Values
     ('ShowName', timestamp);
    
    Select ShowID
      from Show
     Where ShowName = 'ShowName'
      and DateAdded = timestamp;
    
    IMHO a dateAdded (as well as a dateUpdated) field should be included in every table.
    Last edited by Wolffy; January 21st, 2010 at 02:53 PM.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  6. #16
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by Wolffy View Post
    There is also a serious flaw in your logic, if this is a multi-user application. @@identity will return the last identity value inserted, regardless of session. If there is more than one user accesses the application, it is possible that an INSERT statement will be executed (and it doesn't matter what table it's on) between the time of your first INSERT and the query to return the @@identity -- the result being that you will get the WRONG VALUE for @@identity.

    If you must, do it this way (pseudo code):
    Code:
    Set timestamp = currentTime()
    Insert Into Shows
      (ShowName, DateCreated)
    Values
     ('ShowName', timestamp);
    
    Select ShowID
      from Show
     Where ShowName = 'ShowName'
      and DateAdded = timestamp;
    
    IMHO a dateAdded (as well as a dateUpdated) field should be included in every table.
    for this particular sub-system its just one person that will create a show.. however i have used @@IDENTITY to get the bookingID for customers and as you suggested it might be a problem.

  7. #17
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    ill take into account what wolffy said.. i can see that becoming a problem!

    however the reason why my date field wont insert is because i think its calculating the date literally. 12/12/2009 = 4.97760079641613E-04

    I assume id pass the date into a validator? to format it correctly?

  8. #18
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    I believe in Access a date literal is #12/12/2009#
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  9. #19
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by Wolffy View Post
    I believe in Access a date literal is #12/12/2009#
    Code:
    Request.Form("#""ShowDate""#") & ", " & _
    

  10. #20
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by Centurion View Post
    Code:
    Request.Form("#""ShowDate""#") & ", " & _
    
    just to show you that i am trying stuff out:

    Code:
    For x = 1 To 10
    	SQL = "INSERT INTO [performances] (showID, SeatNumber, SeatPrice, performance_time, ShowDate, Status) " & _
    		"VALUES ( " & _
    		showID & ", " & _
    		x & ", " & _
    		Request.Form("SeatPrice") & ", " & _
    		Request.Form("performance_time") & ", " & "#" & _
    		Request.Form("ShowDate") & ", " & "#" & _
    		"'" & Request.Form("Status") & "')"
    	conn.Execute SQL
    
    it shows:

    Code:
    '#22/12/2009'.
    
    just need to work out how to do the other side?

+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast

Similar Threads

  1. if loop problem
    By todd2006 in forum ASP Development
    Replies: 5
    Last Post: July 13th, 2009, 05:01 PM
  2. For Each loop in report
    By tuxalot in forum Microsoft Access
    Replies: 8
    Last Post: March 7th, 2009, 07:21 PM
  3. loop through a collection
    By Shem in forum .NET Development
    Replies: 15
    Last Post: October 17th, 2008, 11:54 AM
  4. Loop / Summary help
    By Rebelle in forum ASP Development
    Replies: 7
    Last Post: April 11th, 2008, 11:12 AM

Bookmarks

Posting Permissions

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

SEO by vBSEO