Vb6+sp5+ado+access表结构:
工号 状态 调整 年
01 在职 0 60
02 在职 0 59
03 在职 0 60
...现在想给把大于N岁的职工,状态改为高退,调整中填入1(1代表己调整)即表变成以下样子
工号 状态 调整
01 离退 1
02 离退 1
03 离退 1
...我自己写的句子:
cmd.CommandText = "select 状态,调整 from 表 where 年>=60"
rst.Open cmd, , adOpenKeyset, adLockBatchOptimistic(或adLockOptimistic)
rst.MoveFirst
Do While Not rst.EOF
rst.Fields!状态.Value = "离退"
rst.Fields!调整.Value = 1
rst.MoveNext
loop
rst.Update(或rst.UpdateBatch )
rst.Close
.....
运行出错提示:键列信息不足或不正确,更新影响到多行
(我打到表看到数据是改过来了,但程序调试会有这个出错提示!,不知如何办才好)
工号 状态 调整 年
01 在职 0 60
02 在职 0 59
03 在职 0 60
...现在想给把大于N岁的职工,状态改为高退,调整中填入1(1代表己调整)即表变成以下样子
工号 状态 调整
01 离退 1
02 离退 1
03 离退 1
...我自己写的句子:
cmd.CommandText = "select 状态,调整 from 表 where 年>=60"
rst.Open cmd, , adOpenKeyset, adLockBatchOptimistic(或adLockOptimistic)
rst.MoveFirst
Do While Not rst.EOF
rst.Fields!状态.Value = "离退"
rst.Fields!调整.Value = 1
rst.MoveNext
loop
rst.Update(或rst.UpdateBatch )
rst.Close
.....
运行出错提示:键列信息不足或不正确,更新影响到多行
(我打到表看到数据是改过来了,但程序调试会有这个出错提示!,不知如何办才好)
改为
cmd.CommandText = "select 工号,状态,调整 from 表 where 年>=60"
即可。
原因:
你提取的记录集里面不带关键字,更新时数据库不知道该更新哪一行,所以报错。
rst.Open cmd, , adOpenKeyset, adLockBatchOptimistic(或adLockOptimistic)
rst.MoveFirst
Do While Not rst.EOF
rst.Fields!状态.Value = "离退"
rst.Fields!调整.Value = 1
rst.Update(或rst.UpdateBatch ) rst.MoveNext
loop
rst.Close
.....
cmd.CommandText = "select 状态,调整 from 表 where 年>=60"
rst.Open cmd, , adOpenKeyset, adLockBatchOptimistic(或adLockOptimistic)
rst.MoveFirst
Do While Not rst.EOF
rst.Fields!状态.Value = "离退"
rst.Fields!调整.Value = 1
rst.MoveNext
loop
rst.Update(或rst.UpdateBatch )
rst.Close
* //================================================你上面这一段程序完全可用下面这两行语句代替sqlText = "update 表 set 状态='离退',调整=1 where 年>=60"
cmd.Execute sqlText================================================或者你的程序中将 rst.Update 语句调入到 Loop 里的 MoveNext 前面。
cmd.Execute sqlText================================================或者你的程序中将 rst.Update 语句调入到 Loop 里的 MoveNext 前面。