sql更新数据报错?

时间:2022-12-21 21:58:43
m_dal.ConnectionOpen()
Dim sql As String
sql = "update 石灰窑生产信息 where 日期 = '" + Me.DataGridView1.Rows(i).Cells(1).Value + "'"
sql += "set 班别 ='" & Me.DataGridView1.Rows(i).Cells(2).Value & "',
                             班次='"&Me.DataGridView1.Rows(i).Cells(3).Value & "'"
sql += "set MgO='" & Me.DataGridView1.Rows(i).Cells(26).Value & "',SiO2='" & Me.DataGridView1.Rows(i).Cells(27).Value & "',S='" & Me.DataGridView1.Rows(i).Cells(28).Value & "'"
m_dal.InsertDelUpdateRecord(sql)

提示where附近错误。

6 个解决方案

#1


where 日期 = '" + Me.DataGridView1.Rows(i).Cells(1).Value + "'"
放在最后面。where 是查出你要修改的条件。

#2


UPDATE 你的表  SET 你的字段= '要改成的值'
WHERE 查询条件= '值'
http://www.w3school.com.cn/sql/sql_update.asp

#3


引用 1 楼 kongwei521 的回复:
where 日期 = '" + Me.DataGridView1.Rows(i).Cells(1).Value + "'"
放在最后面。where 是查出你要修改的条件。


试过了,提示set附近错误

#4


引用 楼主 zss427607 的回复:
m_dal.ConnectionOpen()
Dim sql As String
sql = "update 石灰窑生产信息 where 日期 = '" + Me.DataGridView1.Rows(i).Cells(1).Value + "'"
sql += "set 班别 ='" & Me.DataGridView1.Rows(i).Cells(2).Value & "',
                             班次='"&Me.DataGridView1.Rows(i).Cells(3).Value & "'"
sql += "set MgO='" & Me.DataGridView1.Rows(i).Cells(26).Value & "',SiO2='" & Me.DataGridView1.Rows(i).Cells(27).Value & "',S='" & Me.DataGridView1.Rows(i).Cells(28).Value & "'"
m_dal.InsertDelUpdateRecord(sql)

提示where附近错误。

where位置不对,还有后面多了个Set.

update 石灰窑生产信息 set 班别 ='',班次='',MgO='',SiO2='',S='' where 日期=''

基本的SQL操作语句,楼主要多多练习,总结!

#5


sql = "update 石灰窑生产信息 
sql += "set 班别 ='" & Me.DataGridView1.Rows(i).Cells(2).Value & "',
                             班次='"&Me.DataGridView1.Rows(i).Cells(3).Value & "'"
sql += " ,MgO='" & Me.DataGridView1.Rows(i).Cells(26).Value & "',SiO2='" & Me.DataGridView1.Rows(i).Cells(27).Value & "',S='" & Me.DataGridView1.Rows(i).Cells(28).Value & "' where 日期 = '" + Me.DataGridView1.Rows(i).Cells(1).Value + "'""

#6


谢谢各位热情洋溢的帮助,问题已解决,本人将更新语句变为一句就行,也不知为啥sql+=不行。

#1


where 日期 = '" + Me.DataGridView1.Rows(i).Cells(1).Value + "'"
放在最后面。where 是查出你要修改的条件。

#2


UPDATE 你的表  SET 你的字段= '要改成的值'
WHERE 查询条件= '值'
http://www.w3school.com.cn/sql/sql_update.asp

#3


引用 1 楼 kongwei521 的回复:
where 日期 = '" + Me.DataGridView1.Rows(i).Cells(1).Value + "'"
放在最后面。where 是查出你要修改的条件。


试过了,提示set附近错误

#4


引用 楼主 zss427607 的回复:
m_dal.ConnectionOpen()
Dim sql As String
sql = "update 石灰窑生产信息 where 日期 = '" + Me.DataGridView1.Rows(i).Cells(1).Value + "'"
sql += "set 班别 ='" & Me.DataGridView1.Rows(i).Cells(2).Value & "',
                             班次='"&Me.DataGridView1.Rows(i).Cells(3).Value & "'"
sql += "set MgO='" & Me.DataGridView1.Rows(i).Cells(26).Value & "',SiO2='" & Me.DataGridView1.Rows(i).Cells(27).Value & "',S='" & Me.DataGridView1.Rows(i).Cells(28).Value & "'"
m_dal.InsertDelUpdateRecord(sql)

提示where附近错误。

where位置不对,还有后面多了个Set.

update 石灰窑生产信息 set 班别 ='',班次='',MgO='',SiO2='',S='' where 日期=''

基本的SQL操作语句,楼主要多多练习,总结!

#5


sql = "update 石灰窑生产信息 
sql += "set 班别 ='" & Me.DataGridView1.Rows(i).Cells(2).Value & "',
                             班次='"&Me.DataGridView1.Rows(i).Cells(3).Value & "'"
sql += " ,MgO='" & Me.DataGridView1.Rows(i).Cells(26).Value & "',SiO2='" & Me.DataGridView1.Rows(i).Cells(27).Value & "',S='" & Me.DataGridView1.Rows(i).Cells(28).Value & "' where 日期 = '" + Me.DataGridView1.Rows(i).Cells(1).Value + "'""

#6


谢谢各位热情洋溢的帮助,问题已解决,本人将更新语句变为一句就行,也不知为啥sql+=不行。