使用VB.Net
如果网格单元格值为空,我收到错误,因为“从字符串转换”“到'双''类型无效”
代码(gridview_CellLeave)
Dim z1, z2, z3, z4 As Int32
If grvList.CurrentRow.Cells(1).Value <> "" Then
z1 = grvList.CurrentRow.Cells(1).Value
End If
If grvList.CurrentRow.Cells(2).Value <> "" Then
z2 = grvList.CurrentRow.Cells(2).Value
End If
If grvList.CurrentRow.Cells(3).Value <> "" Then
z3 = grvList.CurrentRow.Cells(3).Value
End If
If grvList.CurrentRow.Cells(4).Value <> "" Then
z4 = grvList.CurrentRow.Cells(4).Value
End If
如何解决此错误。
需要Vb.net代码帮助
答案 0 :(得分:1)
使用TryParse
方法。
Integer.TryParse(text,intVar)
Double.TryParse(text,doubleVar)
答案 1 :(得分:1)
Dim z1, z2, z3, z4 As Int32
If Integer.TryParse(grvList.CurrentRow.Cells(1).Value, z1) Then
'your code here
End If
Dim z1, z2, z3, z4 As Double
If Double.TryParse(grvList.CurrentRow.Cells(1).Value, z1) Then
'your code here
End If
所以其他所有
问候。