求助如何解决:键列信息不足或不正确,更新影响到多行

chen9761 2010-12-27 09:16:04
大家好,请求帮助解决删除ACCESS报表的部分记录,提示错误信息“键列信息不足或不正确,更新影响到多行。”
VB程序如下:

Private Sub Command3_Click()
Dim strQuery As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim ret As Single
Dim ret1, ret2, ret3 As String
Dim mrc As ADODB.Recordset
Dim datestart1, datestart2 As String
Dim dateend1, dateend2 As String

i = MsgBox("ÄãÈ·ÈÏҪɾ³ýÕâЩ¼Ç¼?", vbOKCancel + vbQuestion + vbDefaultButton2, "¾¯¸æ")
If i = vbCancel Then GoTo AAA

datestart1 = Mid(Format(DTPicker1.Value, "yyyy-mm-dd"), 1, 10) & " " & "0:00:00"
dateend1 = Mid(Format(DTPicker2.Value, "yyyy-mm-dd"), 1, 10) & " " & "9:59:59"
datestart2 = Mid(Format(DTPicker1.Value, "yyyy-mm-dd"), 1, 10) & " " & "10:00:00"
dateend2 = Mid(Format(DTPicker2.Value, "yyyy-mm-dd"), 1, 10) & " " & "23:59:59"

If Combo1.Text = "ËùÓÐ" Then
strQuery = "select * from Cashparameter where IDºÅ = 'ºÏ¼Æ' or ÈÕÆÚ >= '" & datestart1 & "' and ÈÕÆÚ <= '" & dateend1 & "' or ÈÕÆÚ >= '" & datestart2 & "' and ÈÕÆÚ <= '" & dateend2 & "' "
Else
strQuery = "select * from Cashparameter where IDºÅ = 'ºÏ¼Æ' or Ãû³Æ = '" & Combo1.Text & " ' and ÈÕÆÚ >= '" & datestart1 & "' And ÈÕÆÚ <= '" & dateend1 & "' or Ãû³Æ = '" & Combo1.Text & " ' and ÈÕÆÚ >= '" & datestart2 & " ' and ÈÕÆÚ <= '" & dateend2 & "' "
'strQuery = "select * from Cashparameter where IDºÅÔ± = '" & Combo1.Text & " ' and ÈÕÆÚ >= '" & DTPicker1.Value & " ' and ÈÕÆÚ <= '" & DTPicker2.Value & " ' "
End If
datPrimaryRS.RecordSource = strQuery
datPrimaryRS.Refresh


If datPrimaryRS.Recordset.RecordCount = 0 Then
GoTo AAA:
Else
For i = 1 To datPrimaryRS.Recordset.RecordCount
'On Error GoTo DeleteErr
With datPrimaryRS.Recordset
.Delete
.MoveNext
' If .EOF Then .MoveLast
End With
'DeleteErr:
' MsgBox Err.Description
Next i
End If



AAA:
Call Delay(0.1, True)
strQuery = "select * from Cashparameter"
datPrimaryRS.RecordSource = strQuery
datPrimaryRS.Refresh
Call Delay(0.1, True)


Command1.Visible = False
Command3.Visible = False
Command2.Visible = False
Combo1.Visible = False
DTPicker1.Visible = False
DTPicker2.Visible = False
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
grdDataGrid.Visible = True
cmdClose.Visible = True
datPrimaryRS.Visible = True
cmdquery.Visible = True
cmdput.Visible = True
cmdRead.Visible = True
'cmdsave.Visible = True
cmdDelete.Visible = True

strQuery = "select * from Cashparameter"
datPrimaryRS.RecordSource = strQuery
datPrimaryRS.Refresh
End Sub
...全文
859 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinaboyzyq 2010-12-28
  • 打赏
  • 举报
回复
数据库中有重复记录时更新有重复的记录会得到这样的错误。
饮水需思源 2010-12-28
  • 打赏
  • 举报
回复
估计是表中存在两条及以上完全相同的记录了
dbcontrols 2010-12-27
  • 打赏
  • 举报
回复
估计是对重复的记录进行了操作。
数据库里加个自动增加的ID字段,防止出现重复记录

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧