首先安裝 Sqlite 必須要先有安裝檔案,因為Sqlite 是一個開源的資料庫,你們可以自己去編譯,我比較懶,用別人編譯好的。按照下面的步驟安裝就行。都是英文的網站,大家注意點哦,別下載錯了。
1、安裝SQLite資料庫
1).開啟瀏覽器進入SQLite首頁,www.sqlite.org。
2).單擊頁面頂部的下載連結(Download)選項,進入下載頁面。
3).滾動滑鼠到“Precompiled Binaries for Windows”,選擇sqlite-shell-win32-x86-3071401.zip(第一項),點擊下載,(你們下載對應的版本,我的是win7我下載的是64位的)
4).使用解壓工具,將其解壓。zip檔案中包含一個sqlite3.exe檔案,可以從解壓檔案所在位置使用sqlite;如果你想從任何目錄下運行CLP,需要將該檔案複製到Windows系統路徑下。預設情況下,Windows中工作的路徑是根分區下的(C:\Windwos\System32)。(注意:我下載到的是sqlite3所以下面在cmd輸入的命令就是sqlite3)
5).開啟運行視窗,輸入CMD,調出Windows命令列視窗。直接在裡面輸入 sqlite3
6).在命令列視窗輸入sqlite3並按斷行符號,將出現SQLite命令列提示符。當SQLite命令列提示符出現時,輸入.help,將出現一列類似相關命令的說明。輸入.exit後退出程式。
:
如果出現如所示,說明你已經安裝成功了。
以上步驟都通過說明已經安裝完成了,不過有點不爽的是這個安裝完成之後是dos命令運行,實在很不爽, 不過有一個圖形介面,我個人感覺比較好,就一起分享給大家。
2、可視化的SQLite資料庫管理工具
管理SQLite資料庫除命令列外,網路上還有很多開源的可視化的SQLite資料庫管理工具,登陸https://sourceforge.net/或者通過其他搜尋引擎(GOOOGLE/BAIDU),輸入【SQLite】可以找到一大片相關工具,比如,SQLite Database Browser、SQLite Administrator... 等等。試用了幾個,比較而言,個人比較喜歡SQLite Administrator,該工具介面支援簡體中文、介面比較簡潔、資料庫相關管理操作相對比較簡便,該工具可以登陸http://sqliteadmin.orbmu2k.de/下載,以下是該工具的一個。
3、在Visual studio 2010下使用SQLite資料庫
登陸http://sqlite.phxsoftware.com/下載最新版的ADO.NET 4.0 Provider for SQLite,下載解壓縮後為一個安裝包。點擊安裝後,可在安裝目錄下發現System.Data.SQLite.dll檔案,同時在安裝過程中該DLL檔案也會自動註冊到Visual studio 2010,可為開發環境引用(見圖)。
簡單一點也可以吧這個dll放到項目中就行。
在Visual studio 2010選擇C#語言,建立新的項目SQLiteView,主介面參見下面的。該項目實現了對SQLite資料庫的資料表的資料記錄的瀏覽、新增、修改和刪除操作功能。
資料庫訪問類DataAccess的代碼: using System; using System.Data; using System.Data.SQLite; namespace SQLiteView { class DataAccess { SQLiteConnection con ; SQLiteCommand command; public DataAccess() { con = new SQLiteConnection("Data Source=test.db3");//test.db3位於debug目錄下 command = con.CreateCommand(); } //讀取資料 public DataTable ReadTable(string tableName) { command.CommandText = "SELECT * FROM " + tableName; SQLiteDataAdapter da = new SQLiteDataAdapter(command); DataTable dt = new DataTable(tableName); da.Fill(dt); return dt; } //修改資料表 public bool UpdateTable(DataTable srcTable, string tableName) { bool isok = false; try { command.CommandText = "SELECT * FROM " + tableName; SQLiteDataAdapter oda = new SQLiteDataAdapter(command); SQLiteCommandBuilder ocb = new SQLiteCommandBuilder(oda); oda.InsertCommand = ocb.GetInsertCommand(); oda.DeleteCommand = ocb.GetDeleteCommand(); oda.UpdateCommand = ocb.GetUpdateCommand(); oda.Update(srcTable); isok = true; } catch (Exception ex) {} return isok; } } } 相關RIDU操作方法的代碼如下: //重新整理資料來源 private void RefreshTable() { this.dataGridView1.DataSource = dba.ReadTable("testone"); } //更新資料來源 private void UpdateTable(DataTable dt) { if (dt != null) { if (dba.UpdateTable(dt, "testone")) { RefreshTable(); MessageBox.Show("OK"); } else MessageBox.Show("Failed"); } } //瀏覽 private void button1_Click(object sender, EventArgs e) { RefreshTable(); } //新增、修改 private void button2_Click(object sender, EventArgs e) { DataTable dt = this.dataGridView1.DataSource as DataTable; UpdateTable(dt); } //刪除 private void button3_Click(object sender, EventArgs e) { DataTable dt = this.dataGridView1.DataSource as DataTable; DataRowView rowview = this.dataGridView1.CurrentRow.DataBoundItem as DataRowView; if (rowview != null) { rowview.Row.Delete(); UpdateTable(dt); } }
通過試用 ,初步感覺SQLite資料庫對SQL語言的支援也不錯、有相關不俗實力的支援人員(Team Dev、社區、論壇)、運行速度較快、普遍關注程度較高、夠輕量級...,其中夠輕量級是其最大的優點和亮點。
這個是我今天的使用的結果。供大家參考