473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Checking if the recordset is null?

nitindel
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
  6.  
  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 61834
DrBunchman
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
  1.  
  2. if rsNew.EOF then
  3.     Response.Write("Not Found")
  4. else
  5.     Response.Write("Found")
  6. end if
  7.  
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
CroCrew
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
  6.  
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
  6.  
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
  6.  
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
markrawlingson
346 Expert 100+
if rsNew.Fields("IP")="NULL" then
-also note that "NULL" is not the same as NULL.
Feb 9 '08 #4
ritman
1
if rsNew.Fields("IP")=vbNULL then
Jun 26 '10 #5
DagJ
2
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

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

Similar topics

4
by: Tom Esker | last post by:
I've got Javascript in a form that adds up all of the numbers in a column of form fields and displays a total. It works great if every field has an initial value of 0, but if any of them are null,...
1
by: excelleinc.com | last post by:
Hi, I'm trying to check if field contains NULL value in MSSQl 2000 database but keep receiving error. asp.net code: If Trim(HLSQLDSet.Tables("mfglinks").Rows(15).Item(0)) Is Null Then...
5
by: Andy G | last post by:
I'm getting this error...Operator is not valid for type 'DBNull' and string "". What is happening is that I'm calling a stored procedure to use the email address to recover a forgotten username. ...
7
by: Vayse | last post by:
i want to check if the following field is null. Dim rsAssets As New ADODB.Recordset rsAssets.Fields("SubIcon").Value) IsNull is no longer supported, so what should I use? Thanks
3
by: Martyn Fewtrell | last post by:
Hi there. I wonder if there was a "correct answer" for Vb.Net (I understand this is quite easy in C#). If im drawing data from a database using a TableAdapter the data ends up in a DataTable....
2
by: misty | last post by:
First i'll introduce myself since I only joined this forum this morning so hey! <waves> Right to the problem. I'm reading values from a html file using the getParameter method to produce an...
5
by: luqman | last post by:
How can I check if dv recordcount isNull ? Best Regards, Luqman Function showRecords(byVal ItemID as Int16) as String Dim SqlArg as New DataSourceSelectArguments Dim dv As New...
2
tolkienarda
by: tolkienarda | last post by:
hi all i dynamicaly generate a select statement and there seems to be a problem with it. below is an example of one that is generated SELECT TITLE, FNMI, SALUTATION, COMPANY, E_MAIL FROM DBASE...
11
by: questionit | last post by:
Dlookup() gives an error if the searchkey (the field i am looking for) is not found in the table. How to check before Dlookup() statement whether the table contains the required value. ...
4
by: barmatt80 | last post by:
I have created an unbound form so that when users enter the information, there is a save button they have to click, checking to make sure a field(txtDocketNo) is not blank. For some reason I cannot...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.