Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to judge the value which I get from database is null? 1

Status
Not open for further replies.

vicky2003

Programmer
May 27, 2003
22
0
0
CA
Hi,
I tried to judge the value I get from database is null or not.I used many expressions to try it, but no use. anyone know it?
the expression is recordSet1.fields("id")


If IsNull(expression) Then

If expression = "" Then

if len(expression) = 0 Then

if expression = nothing Then

if expression = Null Then


tks,
 
If isNull(<recordsetname>(&quot;<fieldname>&quot;)) then

Replace the name of your recordset with everything including the first<> and <fieldname> with id
 
Oh, and remove the quotes around the fieldname if its a numeric value (int, small int, etc) rather than a string (text, varchar, etc)
 
I tried, failed. Could you give me a example?
Ths,
 
Can you show me the code where you created your recordset? I'm guessing it would be:

If isNull(Recordset1(id)) then

if ID is not a string. If it is a string it would be:

If isNull(Recordset1(&quot;id&quot;)) then

Also if you're getting any errors, please post them.
 
The code is:
If( isNull(recordSet(&quot;name&quot;)) then
response.write &quot;no name show&quot;
else
strCurName = recordSet(&quot;name&quot;)
end if

when the field is null, should write &quot;no name show&quot;.but it didn't. it went to strCurName=recordSet(&quot;name&quot;),so I received the error message.

have any idea?
 
Try this:

<%
Dim NoName
If IsNull(recordSet(&quot;name&quot;)) then
NoName = 1
Else
NoName = 0
End if

Dim strCurName
If NoName = 1 Then
response.write(&quot;no name show&quot;)
else
strCurName = recordSet(&quot;name&quot;)
end if

%>


And to test if its evaluating, somewhere in the body put:

<%= NoName %>
 
I tried it. Sometimes it successed,sometimes it failed. so strange.Now it is ok. tks a lot.
 
An easier way to tell if the field is empty is to append an empty string to it. This way a null, or empty string from the database will still show that there's no name.


if recordSet(&quot;name&quot;) & &quot;&quot; = &quot;&quot; then
response.write(&quot;No name shown.&quot;)
else
strCurName = recordSet(&quot;name&quot;)
end if



 
another good thing to do is the following:

if Len(Trim(&quot;^&quot; & recordSet(&quot;name&quot;))) < 1 Then
response.write &quot;no name&quot;
else
response.write recordSet(&quot;name&quot;)
end if

this will check for a string containing only spaces, as well as nulls.
 
correction to above statement..

if Len(Trim(&quot;^&quot; * recordSet(&quot;name&quot;))) = 1 Then

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top