Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 08, 2007 04:24 PM by bhealymonster
Nov 05, 2007 07:13 PM|LINK
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?
Nov 05, 2007 08:08 PM|LINK
This bug has been covered in the Identified Bugs and fixes section.
There are a few solutions and discussions on fixes, you will need to read through it to find the fix.
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;
If( dataRow["columnName"] != DBNull.Value)
myStr = dataRow["columnName"].ToString();
Hope this helps
Nov 08, 2007 04:24 PM|LINK
Thanks I will take a look there and see if I can find it.