VB6:如何在 DataGrid 中顯示 SQLite

VB6:如何在 DataGrid 中顯示 SQLite
Private Sub Form_Load()
Dim sqlstr As String
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection

Dim rs As New ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER=SQLite3 ODBC Driver;Database=" & App.Path & "/database.db;"
conn.Open

rs.Open "SELECT * FROM tblGiat", conn, adOpenKeyset

MsgBox "Total Number of records = " & rs.RecordCount

End Sub

我已成功將資料庫連接到VB6。現在我需要幫助,如何將該資料庫顯示到 DataGrid 中。

答案1

Private Sub Form_Load()
Dim sqlstr As String
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection

Dim rs As New ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER=SQLite3 ODBC Driver;Database=" & App.Path & "/database.db;"
conn.Open

rs.Open "SELECT * FROM tblGiat", conn, adOpenKeyset

MsgBox "Total Number of records = " & rs.RecordCount

Set DataGrid1.DataSource = rs

End Sub

相關內容