您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
小编给大家分享一下mshflexgrid如何联动数据库删除,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
Mshflexgrid属性运用
MSHFlexGrid1.Row 返回当前选中的行号
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 0)代表返回指定行的第一列的值
删除后的刷新思想
1、数据库删除后,重新进行一遍查询(不推荐,消耗性能大)
2、数据库删除后,直接在mshflexgrid上面进行删除指定行,使用语句MSHFlexGrid1.RemoveItem MSHFlexGrid1.Row
RemoveItem方法后面添加一个索引值,就可以删除指定行
文件列表:
界面:
源代码:
Option Explicit
Dim sql As String
Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Command1_Click()
If conn.State = 0 Then
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database3.mdb;Persist Security Info=False"
conn.Open
End If
sql = "insert into [users]([username],[password]) values('" & Text1.Text & "','" & Text2.Text & "')"
Set rs = New ADODB.Recordset
rs.Open sql, conn, adOpenKeyset, adLockBatchOptimistic
'MsgBox "录入成功!"
sql = "select * from users"
rs.Open sql, conn, adOpenKeyset, adLockBatchOptimistic
Set MSHFlexGrid1.DataSource = rs
'表头
MSHFlexGrid1.TextMatrix(0, 0) = "唯一编号"
MSHFlexGrid1.TextMatrix(0, 1) = "账号"
MSHFlexGrid1.TextMatrix(0, 2) = "密码"
End Sub
Private Sub Command2_Click()
If conn.State = 0 Then
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database3.mdb;Persist Security Info=False"
conn.Open
End If
Set rs = New ADODB.Recordset
sql = "select * from users"
rs.Open sql, conn, adOpenKeyset, adLockBatchOptimistic
Set MSHFlexGrid1.DataSource = rs
'表头
MSHFlexGrid1.TextMatrix(0, 0) = "唯一编号"
MSHFlexGrid1.TextMatrix(0, 1) = "账号"
MSHFlexGrid1.TextMatrix(0, 2) = "密码"
End Sub
Private Sub Command3_Click()
If conn.State = 0 Then
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database3.mdb;Persist Security Info=False"
conn.Open
End If
Set rs = New ADODB.Recordset
sql = "delete from [users] where [id]=" & MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 0)
rs.Open sql, conn, adOpenKeyset, adLockBatchOptimistic
'Call Command2_Click '方法1
'方法2
MSHFlexGrid1.RemoveItem MSHFlexGrid1.Row
End Sub
看完了这篇文章,相信你对“mshflexgrid如何联动数据库删除”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。