I have a table with 1 field and it can sometimes be empty.
I want to be able to check in asp page (vbscript) if the
table is empty or not, before any other progress.
How can I do that?
Thanks
I assume it's a one record one field table (some sort of sys stats table)
Will the field potentially contain a Null, an empty string or a zero?
set oRst = oCnn.OpenRecordset("select * from table1"
if (IsNull(oRst.Fields(0)) then ... or
if (oRst.Fields(0) = "" then ... or
if (not oRst.Fields(0)) then
that sort of thing? (doing VB from memory, hope I got it right) Ben
+61 403 395 052
avivit, this is what I usually do when creating my pages. Just below my recordset I redirect my page to an empty one.
Dim myRS
set myRS=server.createobject("ADODB.recordset"
myRS.open sql, "DSN=db1" if myRS.EOF then
response.redirect "emptytable.asp"
end if
QUOTE OF THE DAY
Don't waste time telling people what you are doing or what you are going to do. Results have a way of informing the world.
your choice on this one. I'm not familiar with JavaScript at all so, I don't know how it tell you the table is empty. The script I gave you above will always re-direct you to customized page that tell you the table is empty everytime.
Just in case you don't know, I forgot to remind you to loop thru your table to check if empty
Never mind on my JavaScrip comment, I failed to realized Qaroven was speaking VBScript. QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.
<%
Jr Clown
)
%>
Never mind on my JavaScript comment, I failed to realized Qaroven was speaking VBScript. QUOTE OF THE DAY
The only ideas that will work for you are the ones you put to work.
<%
Jr Clown
)
%>
JrClown, thanks for the effort. I just did not understand what u were saying in your first msg. Now I do, I used it (the idea) and it's working great.
I used the following line to verify I have any record filled out:
if not rs2.EOF then....
That's all I needed. Thanks much
Link9 - Your way is logically and interesting. But why do I
need to check BOF? Isn't it enough if it's EOF?
I just verified it's not EOF, and than go on with my checkings (rs.moveforst etc...).
If it is EOF, I do nothing. Pls explain if I missed something.
Thanks
Well, it's just the convention. It will work every time to see if the recordset is empty. It's what's provided to us by ADO to check for that very thing.
Let's say that for some strange reason, you have 200 records, but by some stroke (or more likely, a mis-stroke), you have moved the recordset to the last record...
Well, then your recordset would be at the .eof, BUT it's not empty.
Every time, no exceptions, the .eof and .bof will both be true if the recordset is empty.
True, for looping, you should use the while not rs.eof, but it's good programming practice to check for the other first, and then I usually even put in the following bit of code (especially in 'trusted components') before I do the while not .eof loop:
Code:
if not (rs.eof and rs.bof) then
rs.movefirst
end if
It will save you the trouble of an error message at some point in the future... guaranteed ;-)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.