更新语句为:
UPDATE  financetable SET '"+ dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText +"' = '" + dataGridView1.CurrentCell.Value + "' WHERE (编号 = '" + dataGridView1.SelectedRows[0].Cells[0].Value + "')
运行时,会报错,提示dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText所在的数据库列名附近有错。例如,我更改日期列的某一日期,会提示'日期'附近有语法错误;若把dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText直接改为日期(表的列名)则不会报错。是哪里出问题了呢?

解决方案 »

  1.   

    单引号去掉
    UPDATE financetable SET "+ dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText +" = '" + dataGridView1.CurrentCell.Value + "' WHERE (编号 = '" + dataGridView1.SelectedRows[0].Cells[0].Value + "'
      

  2.   

    建议不拼接字符串!
    放入查询分析器看下!  set后面是字段名你加引号干嘛
      

  3.   

    UPDATE financetable SET "+ dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText +" = '" + dataGridView1.CurrentCell.Value + "' WHERE (编号 = '" + dataGridView1.SelectedRows[0].Cells[0].Value + "'),这样就可以了,一般遇到问题,最好用查询分析器看看语法有没有问题