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.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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(); |