English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am pulling info form a table in a database to till up lables in my web project. Some of the fields from the table do not contain any data they are null. When my textbox trys to display the data in the data reader for that specific row I get an error saying Conversion from type 'DBNull' to type 'String' is not valid. How can I get around this with out placing a default value in my table like "N/A" if that filed has no data in it. my code looks like this
Comments.Text = drProInfo("Comments")

comments is the filed that has no data in it

2006-12-08 03:48:37 · 2 answers · asked by csdraska 1 in Computers & Internet Programming & Design

2 answers

You have to .ToString() everything. You cannot auto-cast a DBNull to a string, which the text property is.

Comments.Text = drProInfo("Comments").ToString()

2006-12-08 05:00:43 · answer #1 · answered by evolver 6 · 0 0

You could put the text within Try-Catch-End Try.

Try
Comments.Text = drProInfo("Comments")
Catch
Comments.Text = ""
End Try

- Rich

2006-12-09 16:18:21 · answer #2 · answered by Rich 2 · 0 0

fedest.com, questions and answers