I’m trying to find how to test if a String, from a database, is null or not.
Unfortunately, whatever i’m trying, i always find the same exception :
Conversion from type ‘DBNull’ to type ‘String’ is not valid.
CuttingLength1 is a String property into TypedDataRow
Dim dsResults As TypedDataSet
Dim dtResults As TypedDataSet.TypedDataTable
Dim result As TypedDataSet.TypedDataTable.TypedDataRow
Using data As New Bl.Method(MetaData)
dsResults = data.GetData(parameter)
dtResults = dsResults.Typed
result = dtResults.First
If (Not result Is Nothing) Then
If Not result.CuttingLength1 Is Nothing Then
'If Not (DBNull.Value.Equals(result.CuttingLength1)) Then
'If Not IsDBNull(result.CuttingLength1) Then
TextBoxM1.Text = result.CuttingLength1
End If
End If
End Using
I’ve also tried with expressions in captions
>Solution :
You are using a typed DataSet, so every typed DataRow has a dedicated method for each column to determine whether it is NULL or not. Your code should look something like this:
If Not result.IsCuttingLength1Null() Then
TextBoxM1.Text = result.CuttingLength1
End If
You don’t work directly with DBNull in a typed DataSet.
I think that’s what the method will be named but, if not, it will be similar and Intellisense will show you. It may also be a property but I think it’s a method. There is also a corresponding SetCuttingLength1Null method.