问题描述:

Using VB.Net

If the grid cell value is empty, i am getting error as "Conversion from string "" to type 'Double' is not valid"

Code (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

How to solve this error.

Need Vb.net code Help

网友答案:

as suggested, use the TryParse method, thus avoiding also use the try / catch, because that method already handles any format errors.

 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

and so all other

Regards.

网友答案:

Use TryParse method.

Integer.TryParse(text,intVar)
Double.TryParse(text,doubleVar)
相关阅读:
Top