Forum Moderators: open

Message Too Old, No Replies

getrows?

ease of use ..

         

natty

1:07 am on Mar 5, 2004 (gmt 0)

10+ Year Member



hi all,

im having a bit of trouble with the getrows thing. im told it is the way to do things, and it seems nice but..
i was shown this way initially.


Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("dsn=xx")
q="SELECT * FROM tablename"
set oRS=Server.CreateObject("ADODB.recordset")
oRS.open q,oConn
While not oRS.EOF
response.write oRS(1) & oRS("fieldname") ... blah
oRS.MoveNext
Wend
oRS.close
oConn.close

but with getrows like this?


...
q="SELECT * FROM tablename"
set oRS=Server.CreateObject("ADODB.recordset")
oRS.open q,oConn
if not oRS.EOF or oRS.BOF then
arrRows = oRS.getRows()
for x = 1 to?
im stuck
next
else
...
end if


how can i iterate around the arrRows when im unsure of its dimensions..?
must i set the cursor type in order to get the record count and then iterate with that? is there another way?

is the getrows way loads faster?

sorry if this is silly question.

TheNige

1:47 am on Mar 5, 2004 (gmt 0)

10+ Year Member



GetRows creates an array. So, if you return multiple rows with multiple columns you will have a 2-D array.

You would loop through it like:

For x=0 to UBound(arrRows,2)
'Display First Column
response.write(arrRows(0,x))

'Display second column
response.write(arrRows(1,x))
Next

You can also do a loop within the loop to just spit out all the column too. Get faliliar with working with 2-D arrays and it is easy. Also, after you use the GetRows you can just check to see if it contains any data by using IsArray(arrRows) in stead of the RS.EOF. So, as soon as you use get rows you can just close your connection and destroy the RS objects...You don't even really need the RS object you can use the connection.execute(strSQL) i believe..lots of good articles out there.

aspdaddy

1:20 pm on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another way is to use getString() and specify column and row separators, then just response.write a whole table of data