I have an MVC3 app. I make a call to a database, get my data in a dataset and store it in my class. Heres how im storing my data from the dataset
var dt = ds.Tables[0];
var i = 0;
foreach (DataRow dr in dt.Rows)
{
wt = new WorkTasksDto
{
Notes = dr["Notes"].ToString(),
DueDate = Convert.ToDateTime(dr["DueDate"])
}
This is my class member:
[DataMember]
public DateTime? DueDate
{ get; set; }
The field DueDate that comes back from sql server is null and thats fine but when i try to store it in my DueDate field in my class i get the following error:
"Object cannot be cast from DBNull to other types"
How do fix this error? Thanks
Take a look at
DataRow.IsNull