I got the solution which was posted below:
public DataTable ListToDataTable(IEnumerable list) { var dt = new DataTable(); foreach (var info in typeof(T).GetProperties()) { dt.Columns.Add(new DataColumn(info.Name, info.PropertyType)); } foreach (var t in list) { var row = dt.NewRow(); foreach (var info in typeof(T).GetProperties()) { row[info.Name] = info.GetValue(t, null); } dt.Rows.Add(row); } return dt; }
No comments:
Post a Comment