Home > Code and Stuff > VB.NET Check null value with IsDBNull

VB.NET Check null value with IsDBNull

April 19th, 2010

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

Arkie Code and Stuff

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.