运算符'='没有为类型'DBNull'定义,而是类型'布尔'。?/
我打算在出勤时选中已选中但未选中的复选框,但出现在我的代码中。 ''没有为类型'DBNull'定义,而是输入'Boolean'。“...请帮助...您的帮助非常感谢。感谢运算符'='没有为类型'DBNull'定义,而是类型'布尔'。?/
我的代码:
下一页
Dim Present As Integer = 0
Dim Absent As Integer = 0
For a = 0 To Table2___lieDataGridView.RowCount - 1
For b = 0 To Table2___lieDataGridView.ColumnCount - 8
If Table2___lieDataGridView.Rows(a).Cells(b + 5).Value = True Then
Present += 1
Else
Absent += 1
End If
Next
Table2___lieDataGridView.Rows(a).Cells(10).Value = Present
Table2___lieDataGridView.Rows(a).Cells(11).Value = Absent
Present = 0
Absent = 0
Next
之前比较值为true,你应该检查值并非实际的DBNull类型。 这是因为你碰巧在你的数据库中有空值,并且在那种情况下,没有针对布尔值的比较运算符。
例如,看一下这个问题:Handling DBNull data in VB.Net
非常感谢您。我知道了...... gracias – 2014-09-26 05:19:39
非常感谢你@alexw ..........它可以帮到很多 – 2014-09-27 16:33:05
我想你们俩都是,但至少需要15声望 – 2014-09-27 16:33:52
您需要使用IsDBNull功能在进行比较之前检查空值。
If Not IsDBNull(Table2___lieDataGridView.Rows(a).Cells(b + 5).Value) AndAlso Table2___lieDataGridView.Rows(a).Cells(b + 5).Value Then
End If
您需要检查值是'Nothing'还是'DBNull',如果不是,那么您可以安全地将它转换为'Boolean'并进行比较。 – 2014-09-26 04:01:47
感谢您的评论..我在哪里检查它? – 2014-09-26 04:04:55
请参阅下面的答案。您可以使用内置的[IsDBNull](http://msdn.microsoft.com/zh-cn/library/tckcces5(v = vs.90).aspx)函数 – 2014-09-26 04:07:27