代码:
//this is in private void Form3_Load(object sender, EventArgs e)
{string sql = "select * from doctofact WHERE (([doctofact].[docid]=" + l + " and [doctofact].[1userid]='"+str6+"'))";
da = new OleDbDataAdapter(sql, con);
cmd = new OleDbCommandBuilder(da);
dt = new DataTable();
BindingSource dsource = new BindingSource();
dsource.DataSource = dt;
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.ReadOnly = true;
da.Update(dt);
}
private void button3_Click(object sender, EventArgs e) // edit button
{
dataGridView1.ReadOnly = false;
MessageBox.Show("Click on the cell you want to edit and change");
}
private void button4_Click(object sender, EventArgs e) //save button
{
da.Update(dt);
MessageBox.Show("The changes you made have been saved!");
}
现在我的 datagridview 显示了我想要的,所以它只是意味着查询'sql'工作正常。仅当我编辑并尝试通过单击保存按钮进行绑定时才会出现问题。我得到的错误是:
oledb exception missing operator in the query Syntax error (missing operator) in query expression '(((? = 1 AND DocID IS NULL) OR (DocID = ?)) AND ((? = 1 AND FactID IS NULL) OR (FactID = ?)) AND ((? = 1 AND ArticleTitle IS NULL) OR (ArticleTitle = ?)) AND ((? = 1 AND FactPreview IS NULL) OR (FactPreview = ?)) AND ((? = 1 AND 1userid IS NULL) OR (1user'.