public List<object> ShowMessage() { List<object> obj = new List<object>(); DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Name"); dt.Rows.Add("1","AAA"); dt.Rows.Add("2", "BBB"); dt.Rows.Add("3", "CCC"); foreach (DataRow dr in dt.Rows) { obj.Add(dr); } return obj; }
List<object> lst = dt.AsEnumerable().ToList<object>();
public static List<Object> ConvertRowsToList<Object>( DataTable input, Convert<DataRow, Object> conversion) { List<Object> Objval = new List<Object>() foreach(DataRow dr in input.Rows) Objval.Add( conversion(dr) ); return Objval; }
public static IList<object> ConvertTo<object>(DataTable table) { if (table == null) return null; List<DataRow> rows = new List<DataRow>(); foreach (DataRow row in table.Rows) rows.Add(row); return ConvertTo<object>(rows); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)