Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 使用LINQ过滤DBNull_Vb.net_Linq_Null_Dbnull - Fatal编程技术网

Vb.net 使用LINQ过滤DBNull

Vb.net 使用LINQ过滤DBNull,vb.net,linq,null,dbnull,Vb.net,Linq,Null,Dbnull,当我在Where子句中显式过滤掉那些行时,为什么下面的查询会针对桶的NULL值的行引发下面的错误 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)

当我在
Where
子句中显式过滤掉那些行时,为什么下面的查询会针对桶的
NULL
值的行引发下面的错误

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)
引发运行时异常:System.Data.StrongTypingException-表“conformal”中“barrel”列的值为DBNull。


如何重写我的查询/条件以使其按预期工作?

默认情况下,在强类型数据集中,如果字段为空,属性将引发该异常。您需要使用生成的
Is[Field]Null
方法:

Dim query = From row As dbDataSet.conformalRow In dbDataSet.Tables("conformal") _
            Where Not row.IsCalNull() AndAlso tiCal_drop.Text = row.Cal _
            AndAlso Not row.IsTranNull() AndAlso tiTrans_drop.Text = row.Tran _
            AndAlso Not row.IsbarrelNull() _
            Select row.barrel
If query.Count() > 0 Then tiBarrel_txt.Text = query(0)
或DataRow.IsNull方法:

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

Dim query = From row As dbDataSet.conformalRow
        In dbDataSet.Tables("conformal") _ 
        Where row.Cal.Length > 0 AndAlso tiCal_drop.Text = row.Cal _ 
            AndAlso row.Tran.Length > 0 AndAlso tiTrans_drop.Text = row.Tran _ 
            AndAlso row.barrel.Length > 0 _ 
        Select row.barrel