首页 新闻 会员 周边

在数据访问层中如何把多表查询的数据添加到list数据集中

0
悬赏园豆:5 [已解决问题] 解决于 2012-10-17 09:19
private static IList<ProductInfo> GetOrdersBySql(string safeSQL)
{
List<ProductInfo> list = new List<ProductInfo>();
try
{
SqlDataReader read = DBhelperSQL.GetReader(safeSQL);
if (read.HasRows)
{
while (read.Read())
{
ProductInfo product=new ProductInfo();
//OrderInfo order = new OrderInfo();  
//order.CustomerName = read.GetString(0);
//order.OrderDate = read.GetDateTime(1);
product.ProductId = read.GetString(2);
product.ProductName = read.GetString(3);
product.Price = read.GetInt32(4);
product.Imagepath = read.GetString(5);
product.Count = read.GetInt32(6);
product.Description = read.GetString(7);
list.Add(product);
}
}
read.Close();
return list;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
}
就是把我注释的内容也添加到list当中去
smile_yang的主页 smile_yang | 初学一级 | 园豆:196
提问于:2012-10-16 13:47
< >
分享
最佳答案
0
ProductInfo 中增加两个字段CustomerName,OrderDate。Info中的字段不一定要和数据库一样,根据需要可以做适当扩展
收获园豆:5
田林九村 | 老鸟四级 |园豆:2367 | 2012-10-16 13:50
其他回答(1)
0

SqlDataReader 的 NextResult(),然后用同一个 reader 再 Read()

Lepton | 园豆:209 (菜鸟二级) | 2012-10-16 14:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册