已有打开的与此命令相关联的 DataReader,必须首先将它关闭。

[复制链接]
查看11 | 回复1 | 2011-7-9 13:21:26 | 显示全部楼层 |阅读模式
public static IList GetCommBytype(int type)

{

List list = new List();

string sql = "select * from comm where commType=@type";

int commType;//FK

using (SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@type", type)))

{

while (reader.Read())

{

Comm comm = new Comm();

comm.CommId = (int)reader["CommId"];

comm.CommName = (string)reader["CommName"];

commType = (int)reader["CommType"];//FK

comm.CommPrice = (decimal)reader["CommPrice"];

comm.CommNum = (int)reader["CommNum"];

comm.CommSize = (string)reader["CommSize"];

comm.CommLife = (string)reader["CommLife"];
comm.Type = TypeService.GetTypeById(commType);

list.Add(comm);

}

}



reader.Close();

return list;

}
我是根据type查找相关商品 但是怎样才能在循环一个while后 关闭datareader 再执行下一次????????????

回复

使用道具 举报

千问 | 2011-7-9 13:21:26 | 显示全部楼层
关闭数据库连接 再来一次打开数据库连接 reader连接 我以前这样写过 很耗资源...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行