You have only one column and you are not adding it to the DataTable
:
DataColumn datecolumn = new DataColumn();
foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(entity))
{
datecolumn.AllowDBNull = true;
datecolumn.ColumnName = prop.Name == "Id" ? "ID" : prop.Name;
datecolumn.DataType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
columns[jj] = prop.Name == "Id" ? "ID" : prop.Name;
jj++;
}
Instead you have to create them in the loop and then add them(last line in the loop body):
foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(entity))
{
DataColumn datecolumn = new DataColumn();
datecolumn.AllowDBNull = true;
datecolumn.ColumnName = prop.Name == "Id" ? "ID" : prop.Name;
datecolumn.DataType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
columns[jj] = prop.Name == "Id" ? "ID" : prop.Name;
jj++;
dataTable.Columns.Add(datecolumn);
}
0
solved Input array is longer than the number of columns in this table?