【发布时间】:2018-09-21 23:06:42
【问题描述】:
我正在尝试使用 ASP.Net 并生成一个数据库访问层以实现可重用性。我正在使用以下方法将存储过程名称传递给我的 DAL 并执行存储过程,然后将结果作为数据集返回。
但是,在调用类中,我收到了错误
名称 ds 在当前上下文中不存在
我应该更改哪些内容才能访问调用类中返回的数据集?
class DatabaseAccessLayer
{
public DataSet RunSQLServerStoredProcedure(string uspName)
{
using (SqlConnection con = new SqlConnection(essToUse))
{
SqlCommand sqlComm = new SqlCommand(uspName, con);
sqlComm.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlComm;
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}
class Gopher
{
DatabaseAccessLayer dal;
public void PopulateHootersStores()
{
DataRow dr;
dal.RunSQLServerStoredProcedure("ReturnStoredProc");
DataTable dt = ds.Tables[0];
dr = dt.NewRow();
dr.ItemArray = new object[] { 0, "--Select A Store--" };
dt.Rows.InsertAt(dr, 0);
//Adding in All option
dr = dt.NewRow();
dr.ItemArray = new object[] { 1, "All" };
dt.Rows.InsertAt(dr, 1);
cboTest.ValueMember = "StoreNumber";
cboTest.DisplayMember = "StoreName";
cboTest.DataSource = dt;
con.Close();
}
}
【问题讨论】: