|
 |
aspx thread: Testing values returned from a stored proc for null?
Message #1 by "Oliver, Wells" <WOliver@l...> on Tue, 27 Aug 2002 14:29:10 -0700
|
|
This is driving me insane :)
Consider the following:
objDR ("completedDate") = objCom.Parameters
("@completedDate").Value.ToShortDateString ()
objDR is a datarow object, "completedDate" is a string, and "@completedDate"
is a datetime field. So if the field returned by the stored proc is null,
this errors out: Public member 'ToShortDateString' on type 'DBNull' not
found.
I can't seem to find a way to test to see if it's null. I've tried:
If (objCom.Parameters ("@completedDate") is dbNull) Then
objDR("completedDate") = ""
Else
objDR ("completedDate") = objCom.Parameters
("@completedDate").Value.ToShortDateString ()
End If
That errors out: 'dbNull' is a type and cannot be used as an expression.
Also, checking objCom.Parameters ("@completeDate").Value = null also fails,
does as does Value = system.dbnull, etc.
Any tips?
Wells Oliver
Web Application Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
Message #2 by Imar Spaanjaars <Imar@S...> on Tue, 27 Aug 2002 23:33:22 +0200
|
|
Use DBNull.Value.
It's made for checking database NULLs
Imar
At 02:29 PM 8/27/2002 -0700, you wrote:
>This is driving me insane :)
>
>Consider the following:
> objDR ("completedDate") = objCom.Parameters
>("@completedDate").Value.ToShortDateString ()
>
>objDR is a datarow object, "completedDate" is a string, and "@completedDate"
>is a datetime field. So if the field returned by the stored proc is null,
>this errors out: Public member 'ToShortDateString' on type 'DBNull' not
>found.
>
>I can't seem to find a way to test to see if it's null. I've tried:
> If (objCom.Parameters ("@completedDate") is dbNull) Then
> objDR("completedDate") = ""
> Else
> objDR ("completedDate") = objCom.Parameters
>("@completedDate").Value.ToShortDateString ()
> End If
>
>That errors out: 'dbNull' is a type and cannot be used as an expression.
>
>Also, checking objCom.Parameters ("@completeDate").Value = null also fails,
>does as does Value = system.dbnull, etc.
>
>Any tips?
>
>Wells Oliver
>Web Application Programmer
>Leviton Voice & Data
>xxx-xxx-xxxx
>http://www.levitonvoicedata.com
|
|
 |