没有为类型'DBNull'和字符串“1”定义运算符'='。 ? [英] Operator '=' is not defined for type 'DBNull' and string "1" ?
本文介绍了没有为类型'DBNull'和字符串“1”定义运算符'='。 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何解决?
这是我的代码:
Dim x As 整数 = 0
x<> DGVtry.RowCount
如果 dgvtry.Rows( 0 )。单元格( 1 )。值= 1 然后
LBLq1.Text = dgvtry.Rows(x).Cells( 0 )。值
< span class =code-keyword> ElseIf dgvtry.Rows( 0 )。单元格( 1 )。Value = 2 然后
LBLq2.Text = dgvtry.Rows( 0 )。单元格( 0 )。价值
结束 如果
x = x + 1
结束 而
这是我的桌子:
id counter
101 1
104 2
105 3
107 4
提前谢谢!
解决方案
嗯,错误信息非常清楚,你必须正确处理null值(根据您的要求,您可能会生成错误消息或只是跳过它们)。
您可以执行以下操作
如果 NOT IsDbNull(dgvtry.Rows( 0 )。单元格( 1 )) AndAlso dgvtry.Row s( 0 )。单元格( 1 )= 1 然后
< blockquote>
while x<> DGVtry.RowCount
如果 不 IsDBNull(dgvtry.Rows( 0 )。单元格( 1 ))然后
如果 dgvtry.Rows( 0 )。单元格( 1 )。值= 1 然后
LBLq1.Text = dgvtry.Rows(x).Cells( 0 )。值
ElseIf dgvtry.Rows( 0 )。单元格( 1 )。值= 2 然后
LBLq2.Text = dgvtry.Rows( 0 )。单元格( 0 )。值
结束 如果
结束 如果
x = x + 1
End
how to fix?
This is my code:
Dim x As Integer = 0
While x <> DGVtry.RowCount
If dgvtry.Rows(0).Cells(1).Value = "1" Then
LBLq1.Text = dgvtry.Rows(x).Cells(0).Value
ElseIf dgvtry.Rows(0).Cells(1).Value = "2" Then
LBLq2.Text = dgvtry.Rows(0).Cells(0).Value
End If
x = x + 1
End While
This is my table:
id counter
101 1
104 2
105 3
107 4
Thanks in advance!
解决方案
Well, the error message is pretty clear and you have to correctly handle null values (depending on your requirements you may either generate an error message or simply skip them).
you can do as below
If NOT IsDbNull(dgvtry.Rows(0).Cells(1)) AndAlso dgvtry.Rows(0).Cells(1) = "1" Then
While x <> DGVtry.RowCount If Not IsDBNull(dgvtry.Rows(0).Cells(1)) Then If dgvtry.Rows(0).Cells(1).Value = "1" Then LBLq1.Text = dgvtry.Rows(x).Cells(0).Value ElseIf dgvtry.Rows(0).Cells(1).Value = "2" Then LBLq2.Text = dgvtry.Rows(0).Cells(0).Value End If End If x = x + 1 End While
这篇关于没有为类型'DBNull'和字符串“1”定义运算符'='。 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文