您好,登錄后才能下訂單哦!
小編給大家分享一下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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。