using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Dynamic; public static class HelperExtensions { public static List<dynamic> ToDynamic(this DataTable dt) { var dynamicDt = new List&…
public class DataConvert { public static List<T> ConvertDataTable<T>(DataTable dt) { List<T> data = new List<T>(); foreach (DataRow row in dt.Rows) { T item = GetItem<T>(row); data.Add(item); } return data; } public static T…
First of all, we have to fetch the records from the database (MS Sqlserver) into the C# DataTable, or we can add dynamic rows to our DataTable. So our code looks like as written below. //* public DataTable getData() { DataTable dt = new DataTable();…
using System; using System.Data; using System.Configuration; using System.Collections; using System.Collections.Generic; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControl…
很简单的转换功能,这是我在GitHub上复制的一段代码(懒得再去找原地址了),感觉功能还算可以,贴出来分享给大家 /// <summary> /// DataTable to List converter generic class. /// Convert DataTable to a specific class List<>. /// The Class Property Name must be same as the Column Name of the DataTabl…
DataTable的无奈 很多时候,我们需要去操作DataTable.但DataTable的操作,实在是太不方便了.Linq?lambda表达式?统统没有... 特别是对现有结果集做进一步筛选,这样的高频率动作,DataTable却无能为力. 网上很多朋友说用反射实现.那么问题来了,一定要用反射吗? 下面我们用一个不用反射的方式实现: TableToList类 using System; using System.Collections.Generic; using System.Linq; u…