Filtering DBNull With LINQ

Posted by Steven on Stack Overflow See other posts from Stack Overflow or by Steven
Published on 2010-03-08T16:43:43Z Indexed on 2010/03/08 16:51 UTC
Read the original article Hit count: 473

Filed under:
|
|
|

Why does the following query raise the error below for a row with a NULL value for barrel when I explicitly filter out those rows in the Where clause?

Dim query = From row As dbDataSet.conformalRow In dbDataSet.Tables("conformal") _
            Where Not IsDBNull(row.Cal) AndAlso tiCal_drop.Text = row.Cal _
            AndAlso Not IsDBNull(row.Tran) AndAlso tiTrans_drop.Text = row.Tran _
            AndAlso Not IsDBNull(row.barrel) _
            Select row.barrel
If query.Count() > 0 Then tiBarrel_txt.Text = query(0)

Run-time exception thrown : System.Data.StrongTypingException - The value for column 'barrel' in table 'conformal' is DBNull.

How should my query / condition be rewritten to work as I intended?

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about vb.net