recognizing NULL field in IF statement

E

Etayki

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.SqlClient.SqlCommand("SELECT
* FROM Keyword", conn)
Dim myReader As System.Data.SqlClient.SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
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
 
R

rowe_newsgroups

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.SqlClient.SqlCommand("SELECT
* FROM Keyword", conn)
Dim myReader As System.Data.SqlClient.SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
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
 
H

Herfried K. Wagner [MVP]

Etayki said:
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.SqlClient.SqlCommand("SELECT
* FROM Keyword", conn)
Dim myReader As System.Data.SqlClient.SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top