Home All Groups Group Topic Archive Search About

if result = system.dbnull

Author
13 Mar 2006 2:50 PM
cj
in the command window I get:

? result
{System.DBNull}
     [System.DBNull]: {System.DBNull}

I need to check for this in code.  I then tested in the command window

if result = system.DBNull
'DBNull' is a type and cannot be used as an expression.

How can I check to see if result is equal system.dbnull in my code?

Author
13 Mar 2006 3:04 PM
Marina Levit [MVP]
Either of the following:

If IsDBNull(result) Then...
If result = DBNull.Value Then...

Show quoteHide quote
"cj" <cj@nospam.nospam> wrote in message
news:OaXJp1qRGHA.4688@TK2MSFTNGP11.phx.gbl...
> in the command window I get:
>
> ? result
> {System.DBNull}
>     [System.DBNull]: {System.DBNull}
>
> I need to check for this in code.  I then tested in the command window
>
> if result = system.DBNull
> 'DBNull' is a type and cannot be used as an expression.
>
> How can I check to see if result is equal system.dbnull in my code?
Author
13 Mar 2006 3:37 PM
cj
Thanks.  I'll go with IsDBNull(result)

Marina Levit [MVP] wrote:
Show quoteHide quote
> Either of the following:
>
> If IsDBNull(result) Then...
> If result = DBNull.Value Then...
>
> "cj" <cj@nospam.nospam> wrote in message
> news:OaXJp1qRGHA.4688@TK2MSFTNGP11.phx.gbl...
>> in the command window I get:
>>
>> ? result
>> {System.DBNull}
>>     [System.DBNull]: {System.DBNull}
>>
>> I need to check for this in code.  I then tested in the command window
>>
>> if result = system.DBNull
>> 'DBNull' is a type and cannot be used as an expression.
>>
>> How can I check to see if result is equal system.dbnull in my code?
>
>
Author
13 Mar 2006 3:11 PM
pvdg42
Show quote Hide quote
"cj" <cj@nospam.nospam> wrote in message
news:OaXJp1qRGHA.4688@TK2MSFTNGP11.phx.gbl...
> in the command window I get:
>
> ? result
> {System.DBNull}
>     [System.DBNull]: {System.DBNull}
>
> I need to check for this in code.  I then tested in the command window
>
> if result = system.DBNull
> 'DBNull' is a type and cannot be used as an expression.
>
> How can I check to see if result is equal system.dbnull in my code?

Perhaps this will help:

      Visual Basic (Declaration)
Public Shared Function IsDBNull ( _
    value As Object _
) As Boolean

      Visual Basic (Usage)
Dim value As Object
Dim returnValue As Boolean

returnValue = Convert.IsDBNull(value)


--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Author
13 Mar 2006 3:43 PM
cj
I think I sww where you're going with this but I've already changed it
to one of Marina Levit's ideas.

Also I'm not sure how all this would fit in with, result is declared as
an object.  My intention was to declare result as a string but it turns
out when there is nothing to put in it instead of it getting a null
string it gets dbnull.  arrrrgh!  So now result is a object and I can
check to see if it's dbnull if not it's a string.  Seems to work.  So
perhaps I can finish this darn program now.


pvdg42 wrote:
Show quoteHide quote
> "cj" <cj@nospam.nospam> wrote in message
> news:OaXJp1qRGHA.4688@TK2MSFTNGP11.phx.gbl...
>> in the command window I get:
>>
>> ? result
>> {System.DBNull}
>>     [System.DBNull]: {System.DBNull}
>>
>> I need to check for this in code.  I then tested in the command window
>>
>> if result = system.DBNull
>> 'DBNull' is a type and cannot be used as an expression.
>>
>> How can I check to see if result is equal system.dbnull in my code?
>
> Perhaps this will help:
>
>       Visual Basic (Declaration)
> Public Shared Function IsDBNull ( _
>     value As Object _
> ) As Boolean
>
>       Visual Basic (Usage)
> Dim value As Object
> Dim returnValue As Boolean
>
> returnValue = Convert.IsDBNull(value)
>
>
Author
13 Mar 2006 3:19 PM
Armin Zingler
Show quote Hide quote
"cj" <cj@nospam.nospam> schrieb
> in the command window I get:
>
> ? result
> {System.DBNull}
>     [System.DBNull]: {System.DBNull}
>
> I need to check for this in code.  I then tested in the command
> window
>
> if result = system.DBNull
> 'DBNull' is a type and cannot be used as an expression.
>
> How can I check to see if result is equal system.dbnull in my code?

If result is DBnull.value then



Armin
Author
13 Mar 2006 7:03 PM
Herfried K. Wagner [MVP]
"cj" <cj@nospam.nospam> schrieb:
> How can I check to see if result is equal system.dbnull in my code?

'If x Is DBNull.Value Then...' or 'If IsDBNull(x) Then...'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>