我使用以下代码DataGridView从 Access 数据库中填充 a 。如果更新了数据网格,则单击“保存”按钮后,数据库将保存数据。
奇怪的是,这适用于 3 个数据表中的 2 个。对于最后一个它抛出异常:
INSERT INTO 语句中的语法错误
public Tables(string tabName)
{
InitializeComponent();
this.Text = tabName;
this.query = string.Format("SELECT *" + " FROM [{0}]", tabName);
conn.Open();
detailTable = new DataTable();
string tableName = tabName;
string query = string.Format("SELECT * FROM [{0}]", tableName);
OleDbDataAdapter detailAdapter = new OleDbDataAdapter(query, conn);
if (detailAdapter != null)
{
detailAdapter.Fill(detailTable);
}
DataGridView.DataSource = detailTable;
conn.Close();
}
private void BtnSave_Click(object sender, EventArgs e)
{
OleDbCommand comm = new OleDbCommand(query, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(comm);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
adapter.Update(detailTable);
}
即使这些词是保留关键字(尽管我搜索了它们),也没有办法解决这个问题。更多信息 tabName 可以是“Partners”、“Salaries”、“Descriptions”和“Accounts”。它不仅适用于“合作伙伴”。
喵喔喔
相关分类