转换成List集合"/>
C#DataTable转换成List集合
public List<实体类> GetList(){string sql = "";try{ DataTable dt = DBHelperSQL.Getdatatable(sql);//把每条数据循环添加到list集合里边List<T> list = new List<T>();foreach (DataRow item in data.Rows){Table TableName = new Table();AuthorityTB.Id= item["Id"] is DBNull ? 0 : Convert.ToInt32(item["Id"]);AuthorityTB.Name= item["Name"] is DBNull ? string.Empty : Convert.ToString(item["Name"]);list.Add(TableName);}return list;}catch (Exception e){return null;}}
更多推荐
C#DataTable转换成List集合
发布评论