I was trying to generate a Report using Export to Excell, PDF, TextFile. Well I am doing this in MVC. I have a class which I named SPBatch (which is the exact name of my Stored
I would search for nullable and replace it with a string which can be null unlike a DateTime.
foreach (PropertyInfo pi in properties)
{
if (pi.PropertyType.Name.Contains("Nullable"))
myDataType = typeof(String);
else
myDataType = pi.PropertyType;
}
Here is a complete version:
private DataTable CreateDataTable(PropertyInfo[] properties)
{
DataTable dt = new DataTable();
DataColumn dc = null;
foreach (PropertyInfo pi in properties)
{
dc = new DataColumn();
dc.ColumnName = pi.Name;
if (pi.PropertyType.Name.Contains("Nullable"))
dc.DataType = typeof(String);
else
dc.DataType = pi.PropertyType;
// dc.DataType = pi.PropertyType;
dt.Columns.Add(dc);
}
return dt;
}