I have a binding source which has datasource from datatable The table may have fields where its value is Null
When I code this, I get error : 'Public Function xTo0Double() As Double' has no parameters and its return type cannot be indexed
txt_inv_tot.Text = xTo0Double(bs_payh.Current("_INV_TOT")).ToString("N2")
Function xTo0Double(obj As Object) As Double
If IsDbNullNothingEmpty(obj) Then
Return 0
Else
Return CDbl(obj)
End If
End Function
Function IsDbNullNothingEmpty(obj As Object) As Boolean
If obj Is Nothing
Return True
End If
If IsDBNull(obj)
Return True
End If
Try
If String.IsNullOrEmpty(obj)
Return True
End If
Catch ex As Exception
End Try
Return False
End Function
I Did not understand why it gives error... I let the VS IDE correct the error, and it corrected like this
Function xTo0Double(obj As Object) As Object
If IsDbNullNothingEmpty(obj) Then
Return 0
Else
Return CDbl(obj)
End If
End Function
But I want to return Double, not Object
All this coding to avoid using If Then End If in each time I want to check for field value before using it. for example this code works
If IsDBNull(bs_payh.Current("_INV_TOT"))
txt_inv_tot.Text = "0.00"
Else
txt_inv_tot.Text = CDbl(bs_payh.Current("_INV_TOT")).ToString("N2")
End If
But I don't want to use this way each time I want to read field value that could be Null
Is there is a way ?