+ -
当前位置:首页 → 问答吧 → 用RS删除access表中的数据后,马上用另一个RS查询还有此记录?

用RS删除access表中的数据后,马上用另一个RS查询还有此记录?

时间:2011-10-22

来源:互联网

用的是datagrid控件,选中一行后点删除命令,access表中的记录确已删除,但是显示时还在/再点一次删除上一次删除的记录会消失.
代码如下:
Private Sub del(x As String)


Dim conn_del As New ADODB.Connection
Dim rs_del As New ADODB.Recordset
Dim constr As String
Dim dstring As String

dstring = "delete * from p where 姓名='" & x & "'"
constr = "provider=Microsoft.Jet.OLEDB.4.0;Data source =" & App.Path & "/1.mdb"
conn_del.Open constr
rs_del.Open dstring, conn_del, 1, 2
Set rs_del = Nothing
conn_del.Close
Set conn_del = Nothing

End Sub

Private Sub Command_del_Click()

 DataGrid1.AllowDelete = True

If rs_query.State = adStateOpen Then
 
 rs_query.Close
  
 del (dkey) 

End If

If rs_query.State = 1 Then
MsgBox ("open")
End If

 DataGrid1.AllowDelete = False
 
 
 rs_query.Open str, conn_query, adOpenKeyset, adLockPessimistic
  
 
 If rs_query.BOF = True And rs_query.EOF = True Then
   
  label_statistic.Caption = ""
  MsgBox ("没有查到你要找的信息")

Else
  label_statistic.Caption = "总计有" + CStr(rs_query.RecordCount) + "记录"
   
  Set DataGrid1.DataSource = rs_query
  End If
End Sub

作者: liuxingvcvc   发布时间: 2011-10-22

另一个要requery才能获得表的最新情况, 否则只能停留在被打开时的状态

作者: WallesCai   发布时间: 2011-10-22