一:安裝
SQLITE,是一款輕型的資料庫,是遵守ACID的關聯式資料庫管理系統。我直接使用的是http://sqlite.phxsoftware.com/(An open source ADO.NET provider for the SQLite database engine),下載完畢是一個EXE。
然後引用 System.Data.SQLite.dll 程式集;
如果你還想在使用SQLite 中同時使用Linq,則還需要引用 System.Data.SQLite.Linq.dll 程式集;
二:建立資料庫
安裝完畢後,開啟visual studio,建立資料連線,可以看到資料來源多了一項SQLite。
建立串連,如。SQLITE的資料庫,儲存後是一個檔案。
三:資料庫維護
可以在VS中方面的維護SQLITE資料,如:
可以在VS中使用類似SQL查詢分析器的功能,如:
四:混合模式
安裝完畢,可以直接在項目集的引用中,多了
System.Data.SQLite
System.Data.SQLite.Linq
兩個程式集,由於http://sqlite.phxsoftware.com/的System.Data.SQLite是混合模式程式集,是針對“v2.0.50727”版的運行時產生的,在沒有配置其他資訊的情況下,無法在 4.0 運行時中載入該程式集。故需要在App.config中配置如下參數。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
五:我的測試代碼using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
namespace xg_Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//連接字串參考
//string strCon = "Datasource=Test.db3;Pooling=true;FailIfMissing=false";
//"NorthwindEF (SQLite)" connectionString="provider=System.Data.SQLite;metadata=Schemas\NorthwindEFModel.csdl|Schemas\NorthwindEFModel.msl|Schemas\NorthwindEFModel.SQLite.ssdl;Provider Connection String='Data Source=DB\northwindEF.db'"
string strCon = "Data Source=xg_DataBase;Pooling=true;password=sa";
SQLiteConnection con = new SQLiteConnection(strCon);
SQLiteCommand cmd = new SQLiteCommand("select * from student", con);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
學習來源:C# 資料本機存放區方案之 SQLite
Demo 下載