Why i get this error?
Object cannot be cast from DBNull to other types.
when i inserted null value for a numeric datatype in sql server 2005
Here is my code,
if (MeasurementTr.Visible == true)
{
materialIn.measurementId = Convert.ToInt64(DlMeasurement.SelectedValue.ToString());
}
else
{
materialIn.measurementId = Convert.ToInt64(DBNull.Value);
}
EDIT :
Is this right??
materialIn.measurementId = (Convert.ToInt64(DlMeasurement.SelectedValue.ToString()) != 0) ? Convert.ToInt64(DlMeasurement.SelectedValue.ToString()) : 0;