private void btnChange_Click(object sender, EventArgs e)
      {
         try
         {
            sql = "updata Depts set DeptName = '" + dataGView.CurrentRow.Cells[1].Value.ToString() + "'  where DeptNo ='" + dataGView.CurrentRow.Cells[0].Value.ToString() + "'";
            con.OperateData(sql);
            SetBind();
         }
         catch {
            MessageBox.Show("不能做该操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
      }编译后系统总是说“=”附近有语法错误!请高手帮忙!谢谢.........

解决方案 »

  1.   

    DeptNo 是数字类型的吗》数字类型的不加单引号
    sql = "updata Depts set DeptName = '" + dataGView.CurrentRow.Cells[1].Value.ToString() + "' where DeptNo =" + dataGView.CurrentRow.Cells[0].Value.ToString() ;
      

  2.   

    另外要替换引号
    sql = "updata Depts set DeptName = '" + dataGView.CurrentRow.Cells[1].Value.ToString().Replace("'","''") + "' where DeptNo =" + dataGView.CurrentRow.Cells[0].Value.ToString() ;
      

  3.   

    编译后系统总是说“=”附近有语法错误!很明显,LZ,你的Sql语句出问题了where DeptNo ='" + dataGView.CurrentRow.Cells[0].Value.ToString() + "'";
     
    应该是这里出错了,正如楼上所说的一样,你数据库里的字段DeptNO是整型嘛? 是整型的话不用加 单引号了 ''如果字段数据类型这里没有出错,那LZ我建议你调试看看,调试是最好的解决办法,看SQL语句里面的值就知道了。应该就可以找出错误了。不过我想 应该是你的 字段 DeptNo 应该是整型的把? 直接把 单引号 去掉看看结果。
      

  4.   

    这是第二次了
    sql = "update Depts set DeptName = '" + dataGView.CurrentRow.Cells[1].Value.ToString() + "' where DeptNo ='" + dataGView.CurrentRow.Cells[0].Value.ToString() + "'";
    update都写不对
      

  5.   

    ...又是这个update写错的家伙。。