Hi
Can anyone help me in finiding the solution for the DBHull value type casting.
Infact I am storing values into the database and retrieving them into the datagrid. when there is null value in the database it gives me an error " System.InvalidCastException: Object cannot be cast from DBNull to other types.
at System.DBNull.System.IConvertible.ToDateTime(IFormatProvider provider) at
System.Convert.ToDateTime(Object value)".
Any idea how to manage it while I would like to mention that while adding the parameters into the database I am using ("Parameter", DBNull.Value).
Many Thanks.
Loading
Suthish NairPosted Feb 4, 2011, 2:20 PM
Sam HobbsPosted Feb 1, 2011, 4:50 PM
There are many ways. Why not just use an if statement to check for a null? Alternatively you could use try/catch to catch errors, but that seems overkill for this. Alternatively you could use the DateTime.TryParse Method.
Suthish NairPosted Feb 1, 2011, 2:08 PM
post the code that causing probs