C# Convert DataTable to List generic collection
C# snippet below helps to read SQL data to List<T> generic collection without any extensions or frameworks only with SQL and LINQ.
SqlDataSource sdc = SomeFunctionToGetSqlData(string param); DataSourceSelectArguments args = new DataSourceSelectArguments(); DataView dv = sdc.Select(args) as DataView; DataTable dt = dv.ToTable() as DataTable; List<SalaryInfo> allpays = new List<SalaryInfo>(); allpays = (from DataRow row in dt.Rows select new SalaryInfo { description = row["description"].ToString(), sum = Convert.ToDecimal(row["sum"].ToString()), type = row["type"].ToString() }).ToList();