Check whether object is NULL or equal to some value in VB.Net

dotnet
 
on Dec 25, 2012 02:47 AM
4427 Views

I need to make something like :

if isdbnull(value) or value = something then
'do something
else
'do something else
end if

 i get an error using this method , so my question is how do i rewrite it to avoid the "operator not defined for dbnull and something" error ?

Download FREE API for Word, Excel and PDF in ASP.Net: Download
vinayak
 
on Dec 25, 2012 02:51 AM

try this,

 

if value != null || value = ""  then
'do something
else
'do something else
end if

 

dotnet
 
on Dec 25, 2012 03:18 AM

hi,

thanks for ur reply

but, i want to check with dbnull value form the database

like,

 

 If dt.Rows(0)("token_status") = "True" Or dt.Rows(0)("token_status") = DBNull() Then
                    login_details()
                Else
                    lblerror.Text = "Kindly verify user from your email"
                End If

i get error in this

so, how i compare with dbnull

 

vinayak
 
on Dec 25, 2012 03:26 AM

try this,

 

 

 

dt.Rows(0)("token_status") = "True" Or !String.IsNullOrEmpty(dt.Rows(0)("token_status").ToString())

 

dotnet
 
on Dec 26, 2012 11:06 PM

thanks