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

哈了 2011-10-22 12:24:17
用的是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
...全文
44 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
哈了 2011-10-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wallescai 的回复:]
另一个要requery才能获得表的最新情况, 否则只能停留在被打开时的状态
[/Quote]
你是说rs_query要用requery方法?什么时候用?我在调用del()前把rs_query在关闭了的.
熊孩子开学喽 2011-10-22
  • 打赏
  • 举报
回复
另一个要requery才能获得表的最新情况, 否则只能停留在被打开时的状态

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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