CSharp examples for System.Data:DataTable
Fill Data Table
using System.Reflection; using System.Collections; using System.ComponentModel; using System.Data; using System.Text; using System.Linq; using System.Collections.Generic; using System;//from w w w . ja v a 2s .c o m public class Main{ private static DataTable FillDataTable<T>(string tableName, IEnumerable<T> collection) { PropertyInfo[] properties = typeof(T).GetProperties(); DataTable dt = CreateDataTable<T>(tableName, collection, properties); IEnumerator<T> enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { dt.Rows.Add(FillDataRow<T>(dt.NewRow(), enumerator.Current, properties)); } return dt; } }