checking for null parameter values

  • Thread starter Thread starter sean
  • Start date Start date
S

sean

HI There,

How can I check to see if the parameter is returning null? I have tried many
other legacy asp ways of doing things but nothing is working. Could smeone
help me out with my code.

Sean


if myCommand.Parameters("@errmsg1").value ="" Then
do something
else
do something else
end if
 
Hi Sean,

IsDbNull is for every VB.net application equal so as well for aspnet,

You can also use

If value Is DbNull.value which is as well in the right syntax and for every
language the same.
(However, this a VB.net syntax sample)

This checks on a null value in a database, which is not the same as a
Nothing/Null value in memory
(Nothing in VB, Null in C*)

To make it difficult a String is a strange thing, but this is in VB.net all
the same
mystring = nothing
mystring = ""
mystring.IsEmpty
While this is not the same however acts the same
mystring Is Nothing

However that has nothing to do with a DbNull.value or an IfDbNull(value)

(There is as well the datarow.IsNull which is again a DbNull value)

I hope this explains it someting more?

Cor
 
"" isn't the same thing as Null. If you do the following:

string s = "";

if(s.Length > 0) {MessageBox.Show("Something");

Then try... string s;
if(s.Length>0) ... it will blow up b/c s is null right now. Empty strings
are much different than nulls and null values follow the same rules in .NET
as they do in DB's. Null doesn't equal anything, not even itself.

So IsDbNull or DbNull.Value (if you want to set it) is the way to test it,
the same way you have to is Is NULL is SQL vs. = Null . And if you used
SELECT * FROM SOMETABLE where myField = '' then you would guarantee that
you got back no null values.

I know it sounds trivial but it's an important distinction.

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
 
Hi,

It is IsDbNull, not IsNull as it was in VB6. Since you could use VB.NET, not
VB Script in a ASP.NET application, you could use IsDbNull as well. But it
is on a server side, not in a client's script
 
Back
Top