mshflexgrid如何联动数据库删除

小编给大家分享一下mshflexgrid如何联动数据库删除,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、成都网站设计、五通桥网络推广、小程序制作、五通桥网络营销、五通桥企业策划、五通桥品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供五通桥建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com

Mshflexgrid属性运用

MSHFlexGrid1.Row 返回当前选中的行号

MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 0)代表返回指定行的第一列的值

删除后的刷新思想

1、数据库删除后,重新进行一遍查询(不推荐,消耗性能大)

2、数据库删除后,直接在mshflexgrid上面进行删除指定行,使用语句MSHFlexGrid1.RemoveItem MSHFlexGrid1.Row

RemoveItem方法后面添加一个索引值,就可以删除指定行

文件列表:

mshflexgrid如何联动数据库删除

界面:

mshflexgrid如何联动数据库删除

源代码:

Option ExplicitDim sql As StringDim conn As New ADODB.ConnectionDim 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.OpenEnd 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.OpenEnd If
Set rs = New ADODB.Recordsetsql = "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.OpenEnd 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如何联动数据库删除”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


网站栏目:mshflexgrid如何联动数据库删除
网站地址:http://myzitong.com/article/jhddih.html