如何返回一个DataSet数据集
public static DataSet ExecuteDataset( string commandText)
{
SqlConnection con = CreateCon();
SqlCommand Scmd = new SqlCommand();
Scmd.CommandText = commandText;
Scmd.CommandType = CommandType.Text;
Scmd.Connection = con;
con.Open();
Scmd.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(Scmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
------解决方案--------------------public static DataSet ExecuteDataset( string commandText)
{
SqlConnection con = CreateCon();
SqlCommand Scmd = new SqlCommand();
Scmd.CommandText = commandText;
Scmd.CommandType = CommandType.Text;
Scmd.Connection = con;
con.Open();
Scmd.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(Scmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.close() //这里关闭
return ds;
}