vb.net 與 SQLite連線

Dim ModuleSql As String

Dim n As Integer

'SQLite連線
Dim connSQLite As New Data.SQLite.SQLiteConnection
Dim CmdSQLite As New Data.SQLite.SQLiteCommand '定义一个SQL操作
Dim drSQLite As Data.SQLite.SQLiteDataReader

Public Sub Open_SQLite() '打开SQLite連線
connSQLite.ConnectionString = "Data Source=資料庫"
connSQLite.Open() '数据库连接
CmdSQLite.Connection = connSQLite
CmdSQLite.CommandType = CommandType.Text
CmdSQLite.CommandText = ModuleSql
drSQLite = CmdSQLite.ExecuteReader

End Sub

Public Sub Close_SQLite() '关闭SQLite連線
CmdSQLite.Dispose()
connSQLite.Close()
End Sub

ModuleSql = "delete from T1"'刪除
Open_SQLite()
Close_SQLite()

ModuleSql = ("Select COUNT(*) From T1 WHERE (A1 LIKE '" & TextBox1.Text & "')")'查詢
Open_SQLite()
drSQLite.Read()
n = drSQLite.Item(0)
Close_SQLite()

1、下载正确版本的SQLite,主要是32位还是64位

2、将SQLite.Interop.dll和System.Data.SQLite.dll放到bin文件夹的debug文件夹下,然后只需引用System.Data.SQLite.dll就好

3、将项目属性里面的生成里面的平台目标改成x64,当然这是因为我电脑是64位的,如果是32位电脑也许不用这步操作了。

Sub vacuum() '壓縮SQLite資料庫
Dim connection As New SQLite.SQLiteConnection("Data Source=VB1.db")
connection.Open()
Dim oMainQueryR As New SQLite.SQLiteCommand
oMainQueryR = New SQLite.SQLiteCommand
oMainQueryR.Connection = connection
oMainQueryR.CommandText = ("vacuum")
oMainQueryR.ExecuteNonQuery()
connection.Close()
End Sub

上一篇:从C#到Objective-C,循序渐进学习苹果开发(6)--视图控制器的使用


下一篇:9.4、Libgdx简单字符输入