I can't evaluate Text column equal empty

NewComer

Active member
Joined
Jan 2, 2010
Messages
34
Programming Experience
Beginner
I am using MS Access database & I have a table WebRateList with 2 columns ResFrom and ResTo defined as DateTime, another column WebID defined as Text (allow Null)

When I search:

strSQL = "SELECT * FROM WebRateList WHERE ResFrom < #" & ChkOut & "# AND ResTo > #" & ChkIn & "#"

Then it showed "It is in this range!"

But if I scan the same row with column WebID must be emptied, it didn't get in (infact the WebID is empty)

strSQL = "SELECT * FROM WebRateList WHERE ResFrom < #" & ChkOut & "# AND ResTo > #" & ChkIn & "# AND WebID = NULL"
da = New OleDbDataAdapter(strSQL, dbConn)
dt = New DataTable
da.Fill(dt)

If (dt.Rows.Count() > 0) Then
MsgBox("It is in this range!")
End If


Even I defined the following the result is the same

strSQL = "SELECT * FROM WebRateList WHERE ResFrom < #" & ChkOut & "# AND ResTo > #" & ChkIn & "# AND WebID = '' "

Anyone can help?
 
Hey, not sure if you knew why it didn't work with " = Null" but does with "IS NULL"

"= Null" is an illegal statement in SQL.
It's a violation of the ANSI92 SQL specification, which says that a comparison with a null value using the equals operator always gives "false". You should always use the "is" operator when comparing with a null value.

Just remember going forwards to always use IS NULL instead :)

I always found this website helpful for SQL bits
SQL NULL Values - IS NULL and IS NOT NULL
 
The same applies to vb.net, c#, etc as well. Nothing can equal "=" null but it can be null so in vb.net you use:
If Something Is Nothing Then or If SomeField Is DBNull.Value Then

c# you use
if (!SomeField.Equals(DBNull.value)) {
 
Back
Top