关于DataSet的使用问题

来源:百度知道 编辑:UC知道 时间:2024/07/04 19:15:41
本来的语句是:
OracleDataAdapter oda = new OracleDataAdapter("select * from bzrpcxt_fkb where fkb_lx='评分型' order by fkb_id", conn);
DataSet ds = new DataSet();
oda.Fill(ds, "bzrpcxt_fkb");
GridView1.DataSource = ds.Table["bzrpcxt_fkb"];
GridView1.DataBind();
这个正常,但现在有一个类里:
public static DataSet DataSet(string sqlstr)
{
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(ds);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
closeConnection();
}

5行应该是ds.Table[0]吧
还有你那个类名 有点问题吧~~DataSet 不要和C#的类名DATASET重复哦

DataSet ds = AccessDB.DataSet(sqlstr,"表名");

GridView1.DataSource = ds.Tables["表名"];