just curious - is there a shortcut?

Results 1 to 6 of 6

Thread: just curious - is there a shortcut?

  1. #1
    PJ Guest

    Default just curious - is there a shortcut?

    Hello. I&#039;m just wondering if there&#039;s a faster way to do this: <BR><BR>I am selecting the id&#039;s of all records in a table that match certain criteria. I am building an array out of the id&#039;s that are returned (1, 2, 5, 7, 8, 12,...) to use them in a cookie. Right now I build this array by looping through the recordset. <BR><BR>Is there a way to just query the table and have the results simply "be" an array instead of looping to build it?<BR><BR>Example:<BR>"SELECT id FROM table WHERE ..."<BR><BR>&#039; Current procedure:<BR>rc = rs.RecordCount<BR>For i = 1 to rc<BR>myArray = myArray & rs("id")<BR>rs.MoveNext<BR>Next<BR><BR>&#039; Desired procedure:<BR>myArray = all the returned id&#039;s without looping<BR><BR>Any thoughts?

  2. #2
    Eddie Campbell Guest

    Default Yes

    Try using GetRows:<BR><BR>"SELECT id FROM table WHERE ..."<BR>myArray = rs.GetRows<BR><BR><BR>MyArray will now have all the Ids in it.

  3. #3
    PJ Guest

    Default RE: Yes

    Get outta here. Thanks!!!

  4. #4
    PJ Guest

    Default Wait...that didn't work

    Hi again. I tried this...<BR><BR>Set conn = Server.CreateObject("ADODB.Connection")<BR>conn.Op en "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=server;DATABASE=db;UID=id;PWD=pwd;" <BR>Set rs = Server.CreateObject("ADODB.Recordset")<BR>qry = "SELECT co_id FROM co_info WHERE co_id &#060; 25"<BR>rs.Open qry, conn, 1, 3<BR>myArray = rs.GetRows<BR>Response.Write myArray<BR><BR>...and got this error...<BR>"An unhandled data type was encountered."<BR><BR>Do you know why that happened?

  5. #5
    Eddie Campbell Guest

    Default You can't do that

    The problem is that the values are now in an array. You can&#039;t simply do a response.write MyArray.<BR><BR>To refer to the element within the array, you need to refer to them by number. You can use Ubound to find out how many elements there are in the array. Also remember that the 1st element in the array will be 0 not 1<BR><BR>E.g.<BR>myArray = rs.GetRows<BR>For i = 0 to Ubound(myArray,2) + 1<BR>Response.Write "Array element " & i & " = " & myArray(i) & "<BR>"<BR>Next

  6. #6
    PJ Guest

    Default RE: You can't do that

    Thanks. I&#039;ll give it a shot.

Posting Permissions

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