ExecuteReader()与ExecuteNonQuery的问题;
在程序中加入oleDbDataAdapter(oleDBA),两个DataGridView(DGVList);oleDbConnection(oleDBC);然后执行:
如下两个查询是正确的,如果把两个查询换成ExecuteReader()就报一个错误:当前command已经存在一个打开了DataReader必须先关闭才能再次查询;
(第一个查询用于检索所有的记录,第二个用于按用户输入条件检索)
请问如何改正?谢谢
{
string path=Directory.GetCurrentDirectory().ToString()+@ "\ ";
string DBFile = "test.mdb ";
this.OLEDBC.Close();
this.OLEDBC.ConnectionString = @ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + path + DBFile;
try
{
this.OLEDBC.Open();
this.oleDBA.SelectCommand.Connection = this.OLEDBC;
this.oleDBA.SelectCommand.CommandText = @ "select autoid as 序号,name as 姓名,sex as 性别,mark as 分数 " +
@ "from temp order by mark desc ";
this.oleDBA.SelectCommand.ExecuteNonQuery();
DataTable dt = new DataTable();
this.oleDBA.Fill(dt);
this.DGVAllList.DataSource = dt;
}
catch(Exception eMessage)
{
}
finally
{
this.OLED