使用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
Private Sub add_cmd_Click(Index As Integer)
Select Case Index
Case 0
AddUpd = "A"
Case 1
If AddUpd = "A" Then Adodc1.Recordset.AddNew
'¸üÐÂÄãµÄÊý¾Ý
'For i = 0 To 5
' If Text1(i).Text <> "" Then Adodc1.Recordset.Fields(i) = Text1(i).Text
'Next i
Adodc1.Recordset.Update
Case 2
AddUpd = "U"
Case 3
flag = MsgBox("ȷʵҪɾ³ý", vbOKCancel)
If flag = vbOK Then Adodc1.Recordset.Delete
Case 4
If Not Adodc1.Recordset.BOF Then Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveFirst
Case 5
If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast
Case 6
Adodc1.Recordset.MoveLast
Case Else
Adodc1.Recordset.Requery
End If
End Sub
Private Sub add_cmd_Click(Index As Integer)
Select Case Index
Case 0
AddUpd = "A"
Case 1
If AddUpd = "A" Then Adodc1.Recordset.AddNew
'更新你的数据
'For i = 0 To 5
' If Text1(i).Text <> "" Then Adodc1.Recordset.Fields(i) = Text1(i).Text
'Next i
Adodc1.Recordset.Update
Case 2
AddUpd = "U"
Case 3
flag = MsgBox("确实要删除", vbOKCancel)
If flag = vbOK Then Adodc1.Recordset.Delete
Case 4
If Not Adodc1.Recordset.BOF Then Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveFirst
Case 5
If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast
Case 6
Adodc1.Recordset.MoveLast
Case Else
Adodc1.Recordset.Requery
End Select
End Sub
Set DataGrid1.DataSource = Adodc1