469,573 Members | 1,699 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,573 developers. It's quick & easy.

Checking for null

I'm getting this error...Operator is not valid for type 'DBNull' and string
"". What is happening is that I'm calling a stored procedure to use the
email address to recover a forgotten username. If the email does not exist
then I get the above error. After I execute the stored procedure I try and
apparenty this is not catching the error. Should I use a Try...Catch? What
is the correct way to check for nulls in ASP.NET?

If Not myCommand.Parameters("@LOGIN_NAME").Value = "" Then

returnLogin = myCommand.Parameters("@LOGIN_NAME").Value

Else

lblMessage.Text = "Email does not exist in system. Re-enter email or contact
BRM Support"

End If


Nov 18 '05 #1
5 1598
Just a guess but have you tried IsNothing?

If IsNothing(yadda) = True Then
Do Something
End If
"Andy G" <aj*****@iastate.edu> wrote in message
news:OH*************@TK2MSFTNGP10.phx.gbl...
I'm getting this error...Operator is not valid for type 'DBNull' and
string
"". What is happening is that I'm calling a stored procedure to use the
email address to recover a forgotten username. If the email does not
exist
then I get the above error. After I execute the stored procedure I try
and
apparenty this is not catching the error. Should I use a Try...Catch?
What
is the correct way to check for nulls in ASP.NET?

If Not myCommand.Parameters("@LOGIN_NAME").Value = "" Then

returnLogin = myCommand.Parameters("@LOGIN_NAME").Value

Else

lblMessage.Text = "Email does not exist in system. Re-enter email or
contact
BRM Support"

End If

Nov 18 '05 #2
I tried this and I still get the same error. Checking for null should not
be this difficult. Any other ideas?

If IsNothing(myCommand.Parameters("@LOGIN_NAME").Valu e) = True Then

returnLogin = myCommand.Parameters("@LOGIN_NAME").Value

Else

lblMessage.Text = "Email does not exist in system. Re-enter email or contact
BRM Support"

End If

"D. Shane Fowlkes" <sh**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Just a guess but have you tried IsNothing?

If IsNothing(yadda) = True Then
Do Something
End If
"Andy G" <aj*****@iastate.edu> wrote in message
news:OH*************@TK2MSFTNGP10.phx.gbl...
I'm getting this error...Operator is not valid for type 'DBNull' and
string
"". What is happening is that I'm calling a stored procedure to use the email address to recover a forgotten username. If the email does not
exist
then I get the above error. After I execute the stored procedure I try
and
apparenty this is not catching the error. Should I use a Try...Catch?
What
is the correct way to check for nulls in ASP.NET?

If Not myCommand.Parameters("@LOGIN_NAME").Value = "" Then

returnLogin = myCommand.Parameters("@LOGIN_NAME").Value

Else

lblMessage.Text = "Email does not exist in system. Re-enter email or
contact
BRM Support"

End If


Nov 18 '05 #3
Hmmm...another guess. Have you tried IsDBNull?

If IsDBNull(database field here) = False Then
do something
End If


"Andy G" <aj*****@iastate.edu> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl...
I tried this and I still get the same error. Checking for null should not
be this difficult. Any other ideas?

If IsNothing(myCommand.Parameters("@LOGIN_NAME").Valu e) = True Then

returnLogin = myCommand.Parameters("@LOGIN_NAME").Value

Else

lblMessage.Text = "Email does not exist in system. Re-enter email or
contact
BRM Support"

End If

"D. Shane Fowlkes" <sh**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Just a guess but have you tried IsNothing?

If IsNothing(yadda) = True Then
Do Something
End If
"Andy G" <aj*****@iastate.edu> wrote in message
news:OH*************@TK2MSFTNGP10.phx.gbl...
> I'm getting this error...Operator is not valid for type 'DBNull' and
> string
> "". What is happening is that I'm calling a stored procedure to use the > email address to recover a forgotten username. If the email does not
> exist
> then I get the above error. After I execute the stored procedure I try
> and
> apparenty this is not catching the error. Should I use a Try...Catch?
> What
> is the correct way to check for nulls in ASP.NET?
>
> If Not myCommand.Parameters("@LOGIN_NAME").Value = "" Then
>
> returnLogin = myCommand.Parameters("@LOGIN_NAME").Value
>
> Else
>
> lblMessage.Text = "Email does not exist in system. Re-enter email or
> contact
> BRM Support"
>
> End If
>
>
>
>



Nov 18 '05 #4
IsDBNull will and should work!
GDLUCK
PAtrick
"Andy G" wrote:
I tried this and I still get the same error. Checking for null should not
be this difficult. Any other ideas?

If IsNothing(myCommand.Parameters("@LOGIN_NAME").Valu e) = True Then

returnLogin = myCommand.Parameters("@LOGIN_NAME").Value

Else

lblMessage.Text = "Email does not exist in system. Re-enter email or contact
BRM Support"

End If

"D. Shane Fowlkes" <sh**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Just a guess but have you tried IsNothing?

If IsNothing(yadda) = True Then
Do Something
End If
"Andy G" <aj*****@iastate.edu> wrote in message
news:OH*************@TK2MSFTNGP10.phx.gbl...
I'm getting this error...Operator is not valid for type 'DBNull' and
string
"". What is happening is that I'm calling a stored procedure to use the email address to recover a forgotten username. If the email does not
exist
then I get the above error. After I execute the stored procedure I try
and
apparenty this is not catching the error. Should I use a Try...Catch?
What
is the correct way to check for nulls in ASP.NET?

If Not myCommand.Parameters("@LOGIN_NAME").Value = "" Then

returnLogin = myCommand.Parameters("@LOGIN_NAME").Value

Else

lblMessage.Text = "Email does not exist in system. Re-enter email or
contact
BRM Support"

End If



Nov 18 '05 #5
Thanks! IsDBNull worked in addition to a little thing I forgot. I added
Exit Sub inside the condition, otherwise it would redirect which I didn't
want it to do.
"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
IsDBNull will and should work!
GDLUCK
PAtrick
"Andy G" wrote:
I tried this and I still get the same error. Checking for null should not be this difficult. Any other ideas?

If IsNothing(myCommand.Parameters("@LOGIN_NAME").Valu e) = True Then

returnLogin = myCommand.Parameters("@LOGIN_NAME").Value

Else

lblMessage.Text = "Email does not exist in system. Re-enter email or contact BRM Support"

End If

"D. Shane Fowlkes" <sh**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Just a guess but have you tried IsNothing?

If IsNothing(yadda) = True Then
Do Something
End If
"Andy G" <aj*****@iastate.edu> wrote in message
news:OH*************@TK2MSFTNGP10.phx.gbl...
> I'm getting this error...Operator is not valid for type 'DBNull' and
> string
> "". What is happening is that I'm calling a stored procedure to use
the
> email address to recover a forgotten username. If the email does

not > exist
> then I get the above error. After I execute the stored procedure I try > and
> apparenty this is not catching the error. Should I use a Try...Catch? > What
> is the correct way to check for nulls in ASP.NET?
>
> If Not myCommand.Parameters("@LOGIN_NAME").Value = "" Then
>
> returnLogin = myCommand.Parameters("@LOGIN_NAME").Value
>
> Else
>
> lblMessage.Text = "Email does not exist in system. Re-enter email or
> contact
> BRM Support"
>
> End If
>
>
>
>


Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Dave Robinson | last post: by
30 posts views Thread by Michael B Allen | last post: by
99 posts views Thread by Mikhail Teterin | last post: by
5 posts views Thread by A.M | last post: by
4 posts views Thread by Patient Guy | last post: by
2 posts views Thread by Venkata Narayana | last post: by
13 posts views Thread by Karch | last post: by
51 posts views Thread by atv | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.