Hello all-
I was wondering if anyone out there has figured out the .read() feature of the datareader for indicating an empty datareader.
For instance, in asp classic, you just ask:
if not (rs.eof and rs.bof) then
'you have data and can then:
while not rs.eof
'do your stuff here
rs.movenext
wend
else
'you have an empty recordset so:
response.write("Empty recordset"
end if
However, now, we don't get that .eof property of the datareader and when you ask for:
if datareader.read()
then you've already moved past your first record, since .read is sort of a double shot... it moves the record and returns a result (boolean).
The best I've been able to come up with for this type of test is the following:
Dim i As Integer = 0
While datareader.read()
i += 1
'you have data, so do what you need to do
End While
If i = 0 then
'you don't have data so:
someLabel.text = "Sorry, no data"
end if
But this seems like a hack to me -- notice the extra if block there to just check for an empty datareader at the end...
Anyone know of a better way to accomplish this test?
Thanks!
paul
I was wondering if anyone out there has figured out the .read() feature of the datareader for indicating an empty datareader.
For instance, in asp classic, you just ask:
if not (rs.eof and rs.bof) then
'you have data and can then:
while not rs.eof
'do your stuff here
rs.movenext
wend
else
'you have an empty recordset so:
response.write("Empty recordset"
end if
However, now, we don't get that .eof property of the datareader and when you ask for:
if datareader.read()
then you've already moved past your first record, since .read is sort of a double shot... it moves the record and returns a result (boolean).
The best I've been able to come up with for this type of test is the following:
Dim i As Integer = 0
While datareader.read()
i += 1
'you have data, so do what you need to do
End While
If i = 0 then
'you don't have data so:
someLabel.text = "Sorry, no data"
end if
But this seems like a hack to me -- notice the extra if block there to just check for an empty datareader at the end...
Anyone know of a better way to accomplish this test?
Thanks!
paul