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);
}
}编译后系统总是说“=”附近有语法错误!请高手帮忙!谢谢.........
{
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);
}
}编译后系统总是说“=”附近有语法错误!请高手帮忙!谢谢.........
sql = "updata Depts set DeptName = '" + dataGView.CurrentRow.Cells[1].Value.ToString() + "' where DeptNo =" + dataGView.CurrentRow.Cells[0].Value.ToString() ;
sql = "updata Depts set DeptName = '" + dataGView.CurrentRow.Cells[1].Value.ToString().Replace("'","''") + "' where DeptNo =" + dataGView.CurrentRow.Cells[0].Value.ToString() ;
应该是这里出错了,正如楼上所说的一样,你数据库里的字段DeptNO是整型嘛? 是整型的话不用加 单引号了 ''如果字段数据类型这里没有出错,那LZ我建议你调试看看,调试是最好的解决办法,看SQL语句里面的值就知道了。应该就可以找出错误了。不过我想 应该是你的 字段 DeptNo 应该是整型的把? 直接把 单引号 去掉看看结果。
sql = "update Depts set DeptName = '" + dataGView.CurrentRow.Cells[1].Value.ToString() + "' where DeptNo ='" + dataGView.CurrentRow.Cells[0].Value.ToString() + "'";
update都写不对