Checking for null

Discussion in 'ASP .Net' started by Andy G, Nov 22, 2004.

  1. Andy G

    Andy G Guest

    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
     
    Andy G, Nov 22, 2004
    #1
    1. Advertising

  2. Just a guess but have you tried IsNothing?

    If IsNothing(yadda) = True Then
    Do Something
    End If


    "Andy G" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
     
    D. Shane Fowlkes, Nov 22, 2004
    #2
    1. Advertising

  3. Andy G

    Andy G Guest

    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").Value) = 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" <> wrote in message
    news:%...
    > Just a guess but have you tried IsNothing?
    >
    > If IsNothing(yadda) = True Then
    > Do Something
    > End If
    >
    >
    > "Andy G" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >
    > >

    >
    >
     
    Andy G, Nov 22, 2004
    #3
  4. Hmmm...another guess. Have you tried IsDBNull?

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






    "Andy G" <> wrote in message
    news:...
    >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").Value) = 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" <> wrote in message
    > news:%...
    >> Just a guess but have you tried IsNothing?
    >>
    >> If IsNothing(yadda) = True Then
    >> Do Something
    >> End If
    >>
    >>
    >> "Andy G" <> wrote in message
    >> news:...
    >> > 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
    >> >
    >> >
    >> >
    >> >

    >>
    >>

    >
    >
     
    D. Shane Fowlkes, Nov 22, 2004
    #4
  5. 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").Value) = 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" <> wrote in message
    > news:%...
    > > Just a guess but have you tried IsNothing?
    > >
    > > If IsNothing(yadda) = True Then
    > > Do Something
    > > End If
    > >
    > >
    > > "Andy G" <> wrote in message
    > > news:...
    > > > 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
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    >
     
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Nov 23, 2004
    #5
  6. Andy G

    Andy G Guest

    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" <> wrote in message
    news:...
    > 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").Value) = 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" <> wrote in message
    > > news:%...
    > > > Just a guess but have you tried IsNothing?
    > > >
    > > > If IsNothing(yadda) = True Then
    > > > Do Something
    > > > End If
    > > >
    > > >
    > > > "Andy G" <> wrote in message
    > > > news:...
    > > > > 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
    > > > >
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >
    > >
     
    Andy G, Nov 23, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Troy

    Checking For Null DB Fields

    Troy, Aug 21, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    403
    Jeremy Cowles
    Aug 21, 2003
  2. ]-[aTc]-[
    Replies:
    6
    Views:
    20,237
    shebmanchester
    Nov 28, 2011
  3. Jimmy Crider
    Replies:
    3
    Views:
    462
    Chad Z. Hower aka Kudzu
    Feb 18, 2004
  4. excelleinc.com
    Replies:
    1
    Views:
    1,417
    Hermit Dave
    Sep 10, 2004
  5. Replies:
    5
    Views:
    26,683
    Mike Schilling
    Mar 29, 2006
Loading...

Share This Page