本文實例講述了C#簡單訪問SQLite數據庫的方法。分享給大家供大家參考,具體如下:
下載最新版SQLite(http://www.sqlite.org/download.html),其他版本也可以,這里使用的版本是sqlite-3_6_6_1
a.解壓后copy c:/sqlite-3_6_6_1
b.進入cmd模式,進入sqlite-3_6_6_1目錄,執行sqlite3 mytest.db
c.
create table test (seq int,desc varchar(8));insert into mytable1 values (1,'item');
資料建立完成
2.下載System.Data.SQLite(http://sqlite.phxsoftware.com/),安裝,安裝后里面會有詳細的DEMO和文檔。請詳細查看。
3.將mytest.db復制到Bin/Debug目錄下。
4.打開VS2005,參考System.Data.SQLite安裝目錄下的System.Data.SQLite.DLL
using System.Data.SQLite;SQLiteConnection cnn = new SQLiteConnection();cnn.ConnectionString = @"Data Source=mytest.db;Pooling=true;FailIfMissing=false"cnn.Open();SQLiteCommand cmd = new SQLiteCommand();cmd.Connection = cnn;cmd.CommandText = "SELECT * FROM test";SQLiteDataAdapter da = new SQLiteDataAdapter();da.SelectCommand = cmd;DataSet ds = new DataSet();da.Fill(ds);// 分頁查詢顯示語句Select * From test Limit 10 Offset 10;
以上語句表示從Account表獲取數據,跳過10行,取10行
希望本文所述對大家C#程序設計有所幫助。
新聞熱點
疑難解答