如何将DataTable转换成List<T>

如题所述

string sql="你的查询sql语句";
DataTable _dt=SQLHelper.ExcuteQuery(sql);
List<T> _list=null;
if(_dt!=null && _dt.Rows.Count>0)
{
    _list=new List<T>();
    T t=null;
    foreach(DataRow r in _dt.Rows)
    {
        t=new T();
        t.属性1=r["字段名1"].ToString();
        t.属性2=r["字段名2"].ToString();
        ......
        _list.Add(t);
    }
}

温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜