recognizing NULL field in IF statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Etayki

    recognizing NULL field in IF statement

    Hello,

    I am trying to create an IF statement that will recognize whether or
    not a field in the database table is set to some value or if is NULL.

    Dim myCommand As New System.Data.Sql Client.SqlComma nd("SELECT
    * FROM Keyword", conn)
    Dim myReader As System.Data.Sql Client.SqlDataR eader =
    myCommand.Execu teReader(Comman dBehavior.Close Connection)
    While myReader.Read()
    If Not myReader("coil_ search") Then
    ...
    ...
    End If
    End While
    myReader.Close( )

    The "If Not myReader("coil_ search") Then" statement does not seem to
    recognize a NULL field.

    How can I write a statement that will recognize a NULL field?

    Thanks,

    Etay

  • rowe_newsgroups

    #2
    Re: recognizing NULL field in IF statement

    On Apr 20, 7:34 am, Etayki <etay...@gmail. comwrote:
    Hello,
    >
    I am trying to create an IF statement that will recognize whether or
    not a field in the database table is set to some value or if is NULL.
    >
    Dim myCommand As New System.Data.Sql Client.SqlComma nd("SELECT
    * FROM Keyword", conn)
    Dim myReader As System.Data.Sql Client.SqlDataR eader =
    myCommand.Execu teReader(Comman dBehavior.Close Connection)
    While myReader.Read()
    If Not myReader("coil_ search") Then
    ...
    ...
    End If
    End While
    myReader.Close( )
    >
    The "If Not myReader("coil_ search") Then" statement does not seem to
    recognize a NULL field.
    >
    How can I write a statement that will recognize a NULL field?
    >
    Thanks,
    >
    Etay
    IsDbNull(...)

    Thanks,

    Seth Rowe

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: recognizing NULL field in IF statement

      "Etayki" <etayluz@gmail. comschrieb:
      I am trying to create an IF statement that will recognize whether or
      not a field in the database table is set to some value or if is NULL.
      >
      Dim myCommand As New System.Data.Sql Client.SqlComma nd("SELECT
      * FROM Keyword", conn)
      Dim myReader As System.Data.Sql Client.SqlDataR eader =
      myCommand.Execu teReader(Comman dBehavior.Close Connection)
      While myReader.Read()
      If Not myReader("coil_ search") Then
      ...
      ...
      End If
      End While
      myReader.Close( )
      >
      The "If Not myReader("coil_ search") Then" statement does not seem to
      recognize a NULL field.
      >
      How can I write a statement that will recognize a NULL field?
      'If ... Is DBNull.Value Then...'. Take a look at the 'IsDBNull' function
      too.

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

      Comment

      Working...