相比SQL serve或mySQL,Sqlite是一款轻巧的内存级别数据款管理软件,适用于小量数据管理(注:应该不支持联网访问)。
此外,在程序执行过程中,如果使用SQL serve或mySQL数据库,则要求数据库服务也在同时运行,会在一定程度上限制了应用程序的适用范围(比如一台没有装数据库管理软件的计算机将无法使用某些特定应用程序),而使用sqlite则可以很方便的规避了这个问题。
基于此,本人也在实际工作中尝试使用sqlite。
先笼统的说,sqlite与另外两个常用的数据库管理软件在使用VB.NET程序访问的过程中,并没有太大的区别,包含连接(SQLite.SQLiteConnection)、命令(SQLite.SQLiteCommand)、数据适配器(SQLite.SQLiteDataAdapter)这三个常用的函数。
一、 如何在VB.NET程序中引入SQLite?
下载:
SQLite的DLL文件下载地址(下载),打开页面后选择与使用的.NET版本以及CPU位数相同的版本(比如我是用的是:Precompiled Binaries for 32-bit Windows (.NET Framework 3.5 SP1))。下载后将压缩包中的“System.Data.SQLite.dll”文件复制到VB.NET项目的debug目录下。
添加引用:
在VB.NET中通过添加引用的方式将该dll文件添加到项目中。
添加代码:
Imports System.Data.SQLite
二、 常用数据库代码
Imports System.Data.SQLite
Public Class Form1
Private SubButton1_Click(ByValsender As System.Object, ByVale As System.EventArgs)Handles Button1.Click
Try
'创建数据库
Dimdatasource AsString = Application.StartupPath & "/test.db"
System.Data.SQLite.SQLiteConnection.CreateFile(datasource)
'创建连接
DimmySQLiteConnection AsSQLite.SQLiteConnection= New SQLite.SQLiteConnection("DataSource=test.db3;Pooling=true;FailIfMissing=false ")
mySQLiteConnection.Open()
mySQLiteConnection.Close()
'非查询语句(插入(insert)、更新(update)、批量更新(replace))
Dimmycomm As SQLiteCommand = NewSQLiteCommand("sql语句",mySQLiteConnection)
mycomm.ExecuteNonQuery()
DimmyDataadapter AsNew SQLiteDataAdapter("select 语句", mySQLiteConnection)
Dimds As New Data.DataSet
myDataadapter.Fill(ds)
Catch exAs Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
三、 图形化管理软件
网上推荐使用的有sqliteadmin、Sqliteman-1.2.2等,不过使用后感觉还是sqliteadmin比较靠谱。因人而异。