[Solved] How to convert an object having rows into a datatable [closed]


static DataTable GetTable(List<Object> yourObjectList)
{
// This is assuming you have a list of objects
var _firstObject = yourObjectList.First();
var table = new DataTable();

// Do this multiple times for each parameter you have. 
table.Columns.Add(_firstObject.ParamaterName, typeof(string));

foreach(var obj in yourObjectList)
{
table.Rows.Add(obj.ParamaterName, obj.ParamaterName2, etc);
}
return table;
}

I’m assuming you have a list of objects with multiple properties. You need to add a column for each property to the table, then iterate over the list and add rows for each object.

solved How to convert an object having rows into a datatable [closed]