![VB6:如何在 DataGrid 中显示 SQLite](https://linux22.com/image/1586325/VB6%EF%BC%9A%E5%A6%82%E4%BD%95%E5%9C%A8%20DataGrid%20%E4%B8%AD%E6%98%BE%E7%A4%BA%20SQLite.png)
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