468,505 Members | 1,739 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Checking if the recordset is null?

Hi All,

I am working on ASP VBScript...

How can i check the values of a recordset .i.e whether it contains values or not...??

Is NULL considered as a string....??

Actually i want to check on a precondion that if recodset is empty ...i want to take some action
if not empty then some other action..

please reply...

Code taht i have use is:-
Expand|Select|Wrap|Line Numbers
  1. SET objDBdbConnection = Server.CreateObject("ADODB.Connection")
  2. objDBdbConnection.Open Session("ConnectionString")
  3. SET rsNew =server.createobject("ADODB.Recordset")
  4. StrSql = "Select IP from rate where docid=1"
  5. rsNew.open StrSql, objDBdbConnection
  7. if   rsNew.Fields("IP")="NULL" then
  8.     Response.Write("Not Found")
  9. else
  10.     Response.Write("Found")
  11. end if

Thanks :-)
Feb 8 '08 #1
5 58642
979 Expert 512MB
Hi Nitindel,

In order to check if a recordset has anything in it you can simply use the recordset.EOF property. This stands for End Of File and will be True if a recordset is empty. So, using your code:

Expand|Select|Wrap|Line Numbers
  2. if rsNew.EOF then
  3.     Response.Write("Not Found")
  4. else
  5.     Response.Write("Found")
  6. end if
And note that NULL is not considered as a string and is not the same as "".

I hope this help and let me know how you get on,

Dr B
Feb 8 '08 #2
564 Expert 512MB
Hello nitindel,

Checking if the recordset can be done in two ways:

Like DrBunchman said you can use (EOF):
Expand|Select|Wrap|Line Numbers
  1. If (rsNew.EOF) Then
  2.     Response.Write("RecordSet in empty")
  3. Else
  4.     Response.Write("Record(s) are in the RecordSet")
  5. End If
Or using the (RecordCount):
Expand|Select|Wrap|Line Numbers
  1. If (rsNew.RecordCount > 0) Then
  2.     Response.Write("Record(s) are in the RecordSet")
  3. Else
  4.     Response.Write("RecordSet in empty")
  5. End If
To check a field within the recordset is “NULL” then us the (IsNull):
Expand|Select|Wrap|Line Numbers
  1. If (IsNull(rsNew("IP"))) Then
  2.     Response.Write("This Field is Null")
  3. Else
  4.     Response.Write("This Field is not Null")
  5. End If
Keep in mind that “Null” and “” (blank value) are not one in the same.

Hope that explains it a bit more~
Feb 8 '08 #3
346 Expert 100+
if rsNew.Fields("IP")="NULL" then
-also note that "NULL" is not the same as NULL.
Feb 9 '08 #4
if rsNew.Fields("IP")=vbNULL then
Jun 26 '10 #5
You can also use
If rsNew.State = 1 then 'if open then

Unfortunately none of the suggestions above will work if the recordset is NULL, i.e. Set rsNew = Nothing.
Nov 1 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Tom Esker | last post: by
1 post views Thread by excelleinc.com | last post: by
5 posts views Thread by Andy G | last post: by
7 posts views Thread by Vayse | last post: by
3 posts views Thread by Martyn Fewtrell | last post: by
2 posts views Thread by misty | last post: by
5 posts views Thread by luqman | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.