foreach (PropertyInfo PropertyItem in this.GetType().GetProperties())
{
PropertyItem.SetValue(this, objDataTable.Rows[0][PropertyItem.Name.ToString()], null);
}
In one of the loops, I get this exceptional error:
An object of type System.DBNull cannot be converted to type System.String.
The error occurs due to the fact that one of the fields in the database does not have a value (null), so the string property cannot handle this. How can I convert this null to string?
I got this solution
If you know shorter or better, feel free to post it. I am trying to avoid checking in every loop whether the current value is null or not.
peace source
share