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();
A Hidden Visual Studio Trick: Execute Selected Code with double Ctrl+E
What do to with Zone.Identifier files after importing a WSL machine and copying data
Support for SharePoint Server 2019 ends on Tuesday, July 14, 2026