I am having a difficult time with what should be a simple bit of code. The code below loops through the properties of a custom class and gets the value from that class object and stuffs it in the data row.
DataRow row = table.NewRow();
foreach(PropertyInfo p in sfa.GetType().GetProperties())
{
row[p.Name] = p.GetValue(sfa);
}
The problem is the error I get. "Cannot set Column 'columnName' to be null. Please use DBNull instead."
The particular column it is choking on is a DateTime type property. I am all good with using DBNull if that's what it wants. I just don't know and can't figure out HOW? How do I tell the row.column intersection that I want to give it DBNull if it doesn't like System.null.
Thanks in advance for your help!
Aucun commentaire:
Enregistrer un commentaire