使用ado控件和ado对象一起操作数据库,对数据记录集进行更新(添加,删除)都行,但是一旦进行刷新(requery)操作,所有的记录都回到原样,即更新失败。一下是代码,请高手指出问题所在
Private Sub add_cmd_Click(Index As Integer)
Dim flag As String
If Index = 0 Then
Adodc1.Recordset.AddNew
ElseIf Index = 1 Then
Adodc1.Recordset.Save
ElseIf Index = 2 Then
Adodc1.Recordset.Update
ElseIf Index = 3 Then
flag = MsgBox("确实要删除", vbOKCancel)
If flag = vbOK Then
Adodc1.Recordset.Delete
End If
ElseIf Index = 4 Then
If Adodc1.Recordset.BOF = False Then
Adodc1.Recordset.MovePrevious
End If
ElseIf Index = 5 Then
If Adodc1.Recordset.EOF = False Then
Adodc1.Recordset.MoveNext
End If
ElseIf Index = 6 Then
Adodc1.Recordset.MoveLast
Else
Adodc1.Recordset.Requery
End If
End Sub
Private Sub add_cmd_Click(Index As Integer)
Dim flag As String
If Index = 0 Then
Adodc1.Recordset.AddNew
ElseIf Index = 1 Then
Adodc1.Recordset.Save
ElseIf Index = 2 Then
Adodc1.Recordset.Update
ElseIf Index = 3 Then
flag = MsgBox("确实要删除", vbOKCancel)
If flag = vbOK Then
Adodc1.Recordset.Delete
End If
ElseIf Index = 4 Then
If Adodc1.Recordset.BOF = False Then
Adodc1.Recordset.MovePrevious
End If
ElseIf Index = 5 Then
If Adodc1.Recordset.EOF = False Then
Adodc1.Recordset.MoveNext
End If
ElseIf Index = 6 Then
Adodc1.Recordset.MoveLast
Else
Adodc1.Recordset.Requery
End If
End Sub
没仔细建议不要用elseif
用select case
delete,save等操作以后要有adodc1.recordset.update更新保存,
要不没有存储过刷新后就丢失了!