using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
namespace DataBase
{
public class DataAccess
{
//返回DataTable对象
public static DataTable ReturnDataTable(string cmdText)
{
using (DataSet ds=new DataSet())
{
ds=ReturnDataSet(cmdText);
return ds.Tables[0];
}
}
//返回DataSet对象
public static DataSet ReturnDataSet(string cmdText)
{
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
using (OleDbCommand cmd = new OleDbCommand())
{
PrepareCommand(conn, cmd, cmdText);
using (OleDbDataAdapter da = new OleDbDataAdapter())
{
da.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
da.Fill(ds);
return ds;
}
}
}
}
}
}
}
DataSet ds=DataAccess.ReturnDataSet(sql);
报错啊,Cannot assign to 'ds' because it is a 'using variable',要怎么改啊大侠门
------解决方案--------------------------------------------------------
可以做断点测试一下,到底是哪一行的错误
------解决方案--------------------------------------------------------
ding
------解决方案--------------------------------------------------------
如需要阅读该回复,请登录或注册CSDN!
------解决方案--------------------------------------------------------
没看出问题来,楼主单步调一下
------解决方案--------------------------------------------------------
- C# code
public static DataTable ReturnDataTable(string cmdText) { DataSet ds=new DataSet() ds=ReturnDataSet(cmdText); return ds.Tables[0]; }
------解决方案--------------------------------------------------------
去掉using应该就可以了^_^
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
如需要阅读该回复,请登录或注册CSDN!
------解决方案--------------------------------------------------------
试试
- C# code
using (DataSet ds=ReturnDataSet(cmdText)) { return ds.Tables[0]; } }