I am totally new to asp.net and downloaded the club website project. I have not done anything to the events page yet but as soon as i tried to add an event I got the following error.
"Unable to cast object of type 'System.DBNull' to type 'System.String'."
Without knowing more about your code (are you using tableadapters, typed datatables, etc.) is hard to tell. But I'm guessing that your are doing something like:
string myStr = dataRow.columnName;
DBNull is the way ASP abtracts a null value from the database. Note that DBNull is NOT equal to 'null' so you have to check if the value of a column is dbnull before you can use it or convert it to any datatype:
// for typed datasets
if( !dataRow.IscolumnNameNull() )
myStr = dataRow.columnName;
OR
If( dataRow["columnName"] != DBNull.Value)
myStr = dataRow["columnName"].ToString();
Hope this helps
Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue
http://weblogs.asp.net/JaimedelPalacio
bhealymonste...
0 Points
2 Posts
Unable to cast object of type 'System.DBNull' to type 'System.String'.
Nov 05, 2007 07:13 PM|LINK
Hi:
I am totally new to asp.net and downloaded the club website project. I have not done anything to the events page yet but as soon as i tried to add an event I got the following error.
"Unable to cast object of type 'System.DBNull' to type 'System.String'."
Can someone help me out here?
Thanks
Brian
MaineOne
Contributor
2087 Points
469 Posts
Re: Unable to cast object of type 'System.DBNull' to type 'System.String'.
Nov 05, 2007 08:08 PM|LINK
This bug has been covered in the Identified Bugs and fixes section. http://forums.asp.net/t/970081.aspx
There are a few solutions and discussions on fixes, you will need to read through it to find the fix.
jaimedp
Participant
811 Points
151 Posts
Re: Unable to cast object of type 'System.DBNull' to type 'System.String'.
Nov 05, 2007 08:13 PM|LINK
Without knowing more about your code (are you using tableadapters, typed datatables, etc.) is hard to tell. But I'm guessing that your are doing something like:
string myStr = dataRow.columnName;
DBNull is the way ASP abtracts a null value from the database. Note that DBNull is NOT equal to 'null' so you have to check if the value of a column is dbnull before you can use it or convert it to any datatype:
// for typed datasets
if( !dataRow.IscolumnNameNull() )
myStr = dataRow.columnName;
OR
If( dataRow["columnName"] != DBNull.Value)
myStr = dataRow["columnName"].ToString();
Hope this helps
http://weblogs.asp.net/JaimedelPalacio
bhealymonste...
0 Points
2 Posts
Re: Unable to cast object of type 'System.DBNull' to type 'System.String'.
Nov 08, 2007 04:24 PM|LINK
Thanks I will take a look there and see if I can find it.