[求助]C# 如何调用公共类返回的SqlDataReader
我在公共类里的方法
namespace mySql
{
class database
{
public SqlDataReader getreader(string sql)
{
using (SqlConnection mycon = new SqlConnection(con))
{
SqlCommand mycom = new SqlCommand(sql, mycon);
mycon.Open();
mycom.CommandType = CommandType.StoredProcedure;
try
{
SqlDataReader myrea = mycom.ExecuteReader();
return myrea;
}
catch(SqlException ex)
{
throw new Exception(ex.Message);
}
}
}
}
}
调用的代码
database db = new database();
SqlDataReader ownread = db.getreader("maxsell");
while (ownread.Read())
{
string a1 = ownread.GetString(0);
string a2 = ownread.GetDouble(1).ToString();
string a3 = ownread.GetDouble(2).ToString();
label5.Text = string.Format("销售最热产品是{0},销量{1},总价{2}", a1, a2, a3);
string maxmonth = " select month(销售时间)from sell where 商品数量=(select MAX(商品数量)from sell)";
label6.Text = database.getProfit(maxmonth);
&n