VB.NET Check null value with IsDBNull
April 19th, 2010
273 views Goto comments
Leave a comment
Conversion from type ‘DBNull’ to type ‘String’ is not valid.
Conversion from type ‘DBNull’ to type ‘String’ is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.InvalidCastException: Conversion from type ‘DBNull’ to type ‘String’ is not valid.
Solution
If IsDBNull(tabel.Rows(0).Item("columnData")) Then
ddlExample.SelectedValue = "0"
Else
ddlExample.SelectedValue = tabel.Rows(0).Item("columnData")
End If
ddlExample.SelectedValue = "0"
Else
ddlExample.SelectedValue = tabel.Rows(0).Item("columnData")
End If
