Recordset to an array - need a little guidance

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Recordset to an array - need a little guidance

  1. #1

    Default Recordset to an array - need a little guidance

    Hi guys,<BR>Im wanting to generate an array of ID tags from a recordset to use later within my asp page.<BR><BR>At the moment I have tried this...<BR><BR>SQL = "SELECT eventID, ID FROM events WHERE eventID = &#039;" & RS("eventID") & "&#039;"<BR>RS_Open<BR>Dim aTable1Values<BR>aTable1Values = RS.GetRows()<BR>Dim iRowLoop, iColLoop<BR>For iRowLoop = 0 to UBound(aTable1Values, 2)<BR>For iColLoop = 0 to UBound(aTable1Values, 1)<BR>Response.Write(aTable1Values(iColLoop, iRowLoop) & "<BR>")<BR>Next<BR>Response.Write("&#060;p&#062;") <BR>Next &#039;iRowLoop<BR>RS_Close<BR><BR>Which produces this to screen...<BR><BR>48954831135831280121<BR>894<BR><B R>48954831135831280121<BR>895<BR><BR>4895483113583 1280121<BR>896<BR><BR>48954831135831280121<BR>897< BR><BR>48954831135831280121<BR>898<BR><BR>48954831 135831280121<BR>899<BR><BR>But really all I need is something like this...<BR><BR>894,895,896,897,898,899<BR><BR>How would this be acheived?<BR><BR>Thanks,<BR>John<BR><BR>

  2. #2

    Default off to bed...

    Ill be back on tomorrow boys!<BR><BR>Its 11pm here and im bloody tired!<BR><BR>Goodnight!<BR><BR>John

  3. #3
    Join Date
    Dec 1969

    Default Just change your code.

    You&#039;re looping through the columns in your inner loop.<BR><BR>Don&#039;t do that.<BR><BR>Just display the one column that you want to see.

  4. #4

    Default errrr

    remove the break and put the comma in as well?<BR><BR>Im a little unsure, but will give it a try.<BR><BR>Thanks,<BR>John

  5. #5
    Join Date
    Dec 1969

    Default Yeah, makes no sense... even *GET* the eventID in the SQL!<BR><BR>You *know* what it is, because your WHERE clause limited you to it.<BR><BR>But you could do this much simpler:<BR><BR>&#060;%<BR>SQL = "SELECT ID FROM events WHERE eventID = &#039;" & RS("eventID") & "&#039;"<BR>Set RS = yourConn.Execute(SQL)<BR><BR>ids = RS.GetString( , , "", "," )<BR>RS.Close<BR><BR>&#039; chop off trailing comma<BR>Response.Write Left( ids, Len(ids)-1 )<BR><BR>%&#062;<BR><BR>*** HOWEVER ***<BR><BR>It *REALLY* looks suspicious that you use THIS in the sql:<BR><BR>SQL = "SELECT eventID, ID FROM events WHERE eventID = &#039;" & [hl="yellow"]RS("eventID")[/hl] & "&#039;"<BR><BR>HMMMM???<BR><BR>How come you aren&#039;t doing this ALL IN ONE QUERY???<BR><BR>If you are doing this second query once for every record in the first query, then naughty-naughty. Go fix the code to use one and only one query.<BR><BR>

  6. #6

    Default Bill what I am trying to do... create a string of event ID&#039;s so that I can register the person for a recurring event.<BR><BR>If the user selects "Internet Awareness Sessions" and the *GROUP* eventID is 3827hjdhdye99ekej but the individual event ID is 899 then I want to know all of the event IDs with the eventID of 3827hjdhdye99ekej. Did that make sense?<BR><BR>Eg.<BR>Internet Awareness Training 12/08/04<BR>ID 855<BR>EventID 3827hjdhdye99ekej<BR><BR>Internet Awareness Training 16/08/04<BR>ID 856<BR>EventID 3827hjdhdye99ekej<BR><BR>Internet Awareness Training 22/08/04<BR>ID 857<BR>EventID 3827hjdhdye99ekej<BR><BR>And so on....<BR><BR>See how they are individual events that make up an ongoing session of events.<BR><BR>Now when the user says, "register me for all" I need to grab 855, 856, 857 so that when I enter the user registration into the table, I have the correct information.<BR><BR>Does this make it clearer as to what Im trying to acheive?<BR><BR>John

  7. #7

    Default Hows this?

    SQL = "SELECT eventID, ID FROM events WHERE eventID = &#039;" & RS("eventID") & "&#039;"<BR>RS_Open<BR>while not RS.eof<BR>regID = regID & CSTR(RS("ID")) & ","<BR>RS.movenext<BR>wend<BR>RS_Close<BR>end if<BR>session("myevents") = CSTR(regID)<BR>response.write session("myevents") & "<BR>"<BR><BR>Im not this a really silly way of converting the records into a string or is it ok?<BR><BR>I think it gives me what I need...<BR><BR>EG. 1063,1064,1065,1066,1067,1068,1069,1070,1071,1072, 1073,1074,1075,<BR><BR>Any thoughts?<BR><BR>John

  8. #8

    Default ok..I just need to

    get rid of that bloody comma off the end!<BR><BR>1063,1064,1065,1066,1067,1068,1069,107 0,1071,1072,1073,1074,1075,<BR><BR>How is this done?<BR><BR>I cant see anything in the FAQ&#039;S??<BR><BR>John<BR>

  9. #9
    Join Date
    Dec 1969

    Default RE: ok..I just need to

    sString = left(sString, len(sString)-1)<BR><BR>But why don&#039;t you return the values to a dynamic array?

  10. #10
    Join Date
    Dec 1969

    Default Why didn't you like my answer?

    GETSTRING???<BR><BR>No WHILE loop.<BR><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