欢迎加入技术交流QQ群80669150 (附加信息:珠海 -"Lzw )一起学习 !
Tips:DataSet是一个容器,里边装着DataTable,DataTable类似于List<Model>,有行有列,所以两者之间可以进行转换。
//实现代码
private void BindProductTypeTree()
{
GetProductTypeList()
XXXXXXXX
}
//DataSet转换成List<ProductTypeInfo>
public List<ProductTypeInfo> GetProductTypeList()
{
List<ProductTypeInfo> ProductTypeList = new List<ProductTypeInfo>();
MD.spprotypeall sp = new MD.spprotypeall();
sp.Companyid = this.BasePage.LogonUser.CompanyID;
//等待转换的DataSet
DataSet ds = productBL.getprotype(sp);
//
遍历ds中Tables[0]数据
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)//逐行遍历 i 是当前行
{
ProductTypeInfo model = new ProductTypeInfo();
model.CompanyID = Convert.ToInt32(ds.Tables[0].Rows[i]["companyid"]);
model.ParentID = Convert.ToInt32(ds.Tables[0].Rows[i]["parentid"]);
model.SeqNumber = Convert.ToInt32(ds.Tables[0].Rows[i]["seqnumber"]);
model.TypeName = ds.Tables[0].Rows[i]["typename"].ToString();
//将对象插入到List中
ProductTypeList.Add(model);
}
//返回List
return ProductTypeList;
}