数据绑定oledb异常在查询中缺少运算符

时间:2012-07-30 08:34:35

标签: c# data-binding datagridview oledbconnection

CODE:

//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'.

1 个答案:

答案 0 :(得分:0)

我会建议您浏览此链接。 Check This Link

问题是由数据类型不匹配引起的