Binoy asked this 2 years ago

Conversion from type 'DBNull' to type 'String' is not valid

I am getting this error on my VB.net program

Conversion from type 'DBNull' to type 'String' is not valid

The error occurs at the below line

strResult= dtGrid.Rows(i).Item("RESULT")

dtGrid is a data table and what i doing here is to get the "RESULT" column and assign it to string variable.

Please help..


Vikas 2 years ago

convert the data using toString() function and then assign to string variable, So your code should be changed to

strResult= dtGrid.Rows(i).Item("RESULT").toString()

 

 

 

 

williamhold 4 months ago
1 like

This message is getting because the ASP.NET program unable to handle DBNull value. In these cases you can determine whether a value retrieved from a database field is a DBNull value by passing the value of that field to the DBNull.Value.Equals method.

 

If IsDBNull(ds.Tables(0).Rows(i).Item(0)) Then

  Label1.Text = "DBNULL exist in the field "

End If