用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
代码如下:
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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28