private void LoadAppointments() { var conn = new SqlConnection(ConnectionString); var adapter = new SqlDataAdapter("LoadAppointment", conn); var ds = new DataSet(); adapter.Fill(ds); DataTable dataTable = ds.Tables[0]; var myData = ds.Tables[0].AsEnumerable().Select(r => new { column1 = r.Field("column1"), column2 = r.Field("column2"), column3 = r.Field<decimal?>("column3") }); var list = myData.ToList(); }
Quote: You can't query against the DataTable's Rows collection, since DataRowCollection doesn't implement IEnumerable<t>. You need to use the AsEnumerable() extension for DataTable
foreach (DataRow row in ds.Tables[0].Rows) { IEnumerable<object> asEnumerable = row.ItemArray.AsEnumerable(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)