Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

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

  Asked By: Sunil    Date: Feb 09    Category: Asp.net    Views: 7026
  

my code:


dim dbEditorTitle as string

dbEditorTitle = objDataReader("adminTitle")

sometimes the field from db is empty or NULL and im getting:

Cast from type 'DBNull' to type 'String' is not valid.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Sheryl Morgan     Answered On: Feb 09

You can do a test for DBNull.Value first:
E.g.


If objDataReader("adminTitle") Is DBNull.Value Then
dbEditorTitle = "--"
Else
dbEditorTitle = objDataReader("adminTitle")
End If

 
Answer #2    Answered By: Brian Ross     Answered On: Feb 09

Check for NULL... or make query with ISNULL(column_name, '') function.

 
Didn't find what you were looking for? Find more on Cast from type 'DBNull' to type 'String' is not valid Or get search suggestion and latest updates.




Tagged: