Difference between nothing and system.DBNull
I am working in VB.NET and I am curious about the difference between Nothing
and System.DBNull
.
When I run the save request at that time, I give the value from the grid at runtime as shown below:
gvMain.Rows(j).Cells("Brand").Value.ToString()
But it shows me an error when it matters Nothing
, and it works great when it matters System.DBNull
.
What to do in this case?
thanks in advance
source to share
Nothing
is of type System.Object.
It represents the default for any data type.
DBNull.Value
is of type System.DBNull
If something is displayed as System.DBNull
, it means that even if it doesn't matter, it has a valid pointer. As you may have found out, it cannot be converted to a string, integer, etc. You should check (preferably using IsDBNull
.
If IsDBNull(gvMain.Rows(j).Cells("Brand").Value) Then
Return String.Empty
Else
Return gvMain.Rows(j).Cells("Brand").Value.ToString().Trim()
End If
source to share