- List
licenselist = new List ();
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ananth GPosted Dec 15, 2016, 1:42 AM
Harshal PatilPosted Dec 16, 2016, 4:25 AM
public DataTable ToDataTable(List items)
{
DataTable dataTable = new DataTable(typeof(T).Name);
//Get all the properties
PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in Props)
{
//Setting column names as Property names
dataTable.Columns.Add(prop.Name);
}
foreach (T item in items)
{
var values = new object[Props.Length];
for (int i = 0; i < Props.Length; i++)
{
//inserting property values to datatable rows
values[i] = Props[i].GetValue(item, null);
}
dataTable.Rows.Add(values);
}
//put a breakpoint here and check datatable
return dataTable;
}
Khaja MoizuddinPosted Dec 15, 2016, 12:20 PM
Midhun TpPosted Dec 15, 2016, 1:35 AM
Dinesh SanthalingamPosted Dec 15, 2016, 1:33 AM
Ananth GPosted Dec 15, 2016, 1:28 AM
Dinesh SanthalingamPosted Dec 15, 2016, 1:26 AM
Jasbeer SinghPosted Dec 15, 2016, 1:21 AM
Ananth GPosted Dec 15, 2016, 1:15 AM