使用OleDbDataAdapter.Fill()抛出异常
本文关键字:抛出异常 Fill OleDbDataAdapter 使用 | 更新日期: 2023-09-27 18:04:50
OleDbConnection conn = new OleDbConnection(OLEDBhelper.ConnectionString);
String SqlStt = "SELECT * FROM Groups where CodeTribe=@Code";
OleDbCommand command = new OleDbCommand(SqlStt, conn);
command.Parameters.AddWithValue("@Code", p);
conn.Open();
OleDbDataAdapter Data = new OleDbDataAdapter(command.CommandText, conn);
conn.Close();
DataSet ds = new DataSet();
Data.Fill(ds);
foreach (DataRow row in ds.Tables[0].Rows)
{
DataGridViewRow NewRow = (DataGridViewRow)dataGridViewGroups.Rows[0].Clone();
NewRow.Cells[0].Value = row["CodeGroup"].ToString();
NewRow.Cells[1].Value = row["NameGroup"].ToString();
dataGridViewGroups.Rows.Add(NewRow);
}
p是一个数
连接正常,我在
处得到一个OleDB异常Data.Fill(ds);
我想我的查询有问题,但我不知道在哪里
尝试移动.Close();
OleDbDataAdapter Data = new OleDbDataAdapter(command.CommandText, conn);
DataSet ds = new DataSet();
Data.Fill(ds);
foreach (DataRow row in ds.Tables[0].Rows)
{
DataGridViewRow NewRow = (DataGridViewRow)dataGridViewGroups.Rows[0].Clone();
NewRow.Cells[0].Value = row["CodeGroup"].ToString();
NewRow.Cells[1].Value = row["NameGroup"].ToString();
dataGridViewGroups.Rows.Add(NewRow);
}
conn.Close();//You might be able to add this under the Data.Fill()