vbnet 要使用 SQLite 資料庫 (ADO.NET) System.Data.SQLite
一定要採用:SQLite shell 建資料庫 , 用VS 來建資料表,欄位等(亦可有指令來新建)
在使用過程:試了 SQLite Administrator , SQLite Spy 等2個工具去建資料表後
使用 vbnet 要去開資料庫均造成無法開啟的訊息!!
----
底下參考SQLite in VB.net - Page 2 的範例寫的! (至於 VB6 有空再來測)
--
Imports System.Data
Imports System.Data.SQLite
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
SQLconnect.ConnectionString = "Data Source=" & Application.StartupPath & "\test.db3" & ";"
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
SQLcommand.CommandText = "SELECT * FROM test"
Dim SQLreader As SQLiteDataReader = SQLcommand.ExecuteReader()
lst_records.Items.Clear()
While SQLreader.Read()
lst_records.Items.Add(String.Format("ID = {0}, name = {1}", SQLreader(0), SQLreader(1)))
'Optionally use the variable names to identify columns
'De lst_records.Items.Add(String.Format("ID = {0}, Title = {1}, Description = {1}", SQLreader("id"), SQLreader("title"), SQLreader("description")))
End While
SQLcommand.Dispose()
SQLconnect.Close()
End Sub
End Class
沒有留言:
張貼留言