Using GetRows()

C

Croney69

I am getting information out of a table to place into to
an Array.
rs=DataConn.Execute(strSQL)

At this point I place it into the array

objArray=rs.GetRows()

But how do I handle things if the rs came back blank?

What happens is that the loop encounters an error?
 
J

Jon Mundsack

Croney69 said:
I am getting information out of a table to place into to
an Array.
rs=DataConn.Execute(strSQL)

At this point I place it into the array

objArray=rs.GetRows()

But how do I handle things if the rs came back blank?

What happens is that the loop encounters an error?

If rs.RecordCount > 0 Then
objArray = rs.GetRows()
'do stuff with array
Else
'handle "no records" condition
End If

HTH-Jon
 
C

Croney69

Sorry I should have mentioned this is a function to
provide an array, which is then use.

I am well a wear of the "if then else" and "eof".
What I want to know is that after calling my function
MyArray= GetInfo(sql)

I will know if to proceed or not depending on the result.

This is what I have seen but it dose not work

1. If not rs.eof then
2. ObjArray=rs.GetRows()
3. Else
4. ObjArray=dataconn.execute("Select 'EOF'").GetRows()
5. End if

I get an error on line 4
 
J

Jon Mundsack

Croney69 said:
Sorry I should have mentioned this is a function to
provide an array, which is then use.

I am well a wear of the "if then else" and "eof".
What I want to know is that after calling my function
MyArray= GetInfo(sql)

I will know if to proceed or not depending on the result.

This is what I have seen but it dose not work

1. If not rs.eof then
2. ObjArray=rs.GetRows()
3. Else
4. ObjArray=dataconn.execute("Select 'EOF'").GetRows()
5. End if

I get an error on line 4

So, if rs contains records, you want ObjArray to contain the GetRows, and if
rs doesn't contain records, you want it to contain a single array element
holding the word EOF? If so, then this is what you want:

If not rs.eof then
ObjArray=rs.GetRows()
Else
ReDim ObjArray(0)
ObjArray(0) = "EOF"
End if

I see no reason to involve the dataconn.execute call and another GetRows,
unless I'm still missing something.

HTH-Jon
 
K

Kris Eiben

AFAIK you need to select FROM a table or other database object (view,
stored proc, etc). And, even if that line 4 syntax worked, you'd be
setting objArray to an array if it had records and a recordset if it
didn't, which will probably cause problems later.

I might set it up like this:
if not rs.EOF then
objArray = rs.GetRows()
else
dim objArray(1,1)
objArray(0,0) = "No Records" ' or whatever flag value you want
end if
Then, I could check objArray(0,0) for "No Records" before processing.
 
B

Bob Barrows

Croney69 said:
I am getting information out of a table to place into to
an Array.
rs=DataConn.Execute(strSQL)

At this point I place it into the array

objArray=rs.GetRows()

But how do I handle things if the rs came back blank?

What happens is that the loop encounters an error?

This is my SOP with GetRows:

if not rs.eof then
ar=rs.getrows
end if
rs.close
set rs=nothing
if isarray(ar) then
'you have data
else
'you don't have data
end if

HTH,
Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top