Reputation:
i work on C# vs05 ...
DataTable dt=CreateTable(_oGeneralReports);//collection _oGeneralReports
i want a method that Converting a Collection into a DataTable ..dt contain the collection value.....help me to get this
Upvotes: 0
Views: 1934
Reputation: 2484
You'll have to make a new data table and manually add all the columns to it, then loop through the collection adding each item to the table. e.g
public DataTable CreateTable(ICollection items)
{
DataTable table = new DataTable();
table.Columns.Add("Column1", typeof(int));
table.Columns.Add("Column2", typeof(string));
foreach (Item item in items)
{
DataRow row = table.NewRow();
row["Column1"] = item.Column1;
row["Column2"] = item.Column2;
table.Rows.Add(row);
}
return table;
}
Upvotes: 1