標籤:
建立項目後,在程式包管理主控台中輸入:
Install-Package linq2db.SQLite
斷行符號。
中是之前翻&牆安裝過(順便贊一下GFW:我XXX!),本次安裝是從本機快取安裝的。
安裝成功之後,看看解決方案中的項目會有如下變化:
瞬間搞定的即視感!有木有?
最後奉上C#操作sqlite的例子,昨天剛剛研究出來的 ,新鮮的哦!
using System;using System.IO;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Data.SQLite;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { using (SQLiteConnection conn = new SQLiteConnection("Data Source=d:\\abc.db")) { conn.Open(); DropTable(conn); CreateTable(conn); InsertData(conn); //GetData(conn); conn.Close(); } } private static void CreateTable(SQLiteConnection conn) { SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = @"CREATE TABLE Question( ID integer primary key, QuestionContent text, HtmlContent text)"; cmd.ExecuteNonQuery(); } private static void InsertData(SQLiteConnection conn) { SQLiteCommand cmd = conn.CreateCommand(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 100; i++) { sb.AppendFormat("INSERT INTO Question (ID,QuestionContent,HtmlContent) VALUES ({0},'試題內容:{1}','試題答案{2}');", i, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); } cmd.CommandText = sb.ToString(); cmd.ExecuteNonQuery(); } private static void GetData(SQLiteConnection conn) { SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM Question"; SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { var obj = new { Id = reader.GetInt32(0), QuestionContent = reader.GetString(1), HtmlContent = reader.GetString(2) }; Console.WriteLine(string.Format("Id:{0};QuestionContent={1};HtmlContent={2}", obj.Id, obj.QuestionContent, obj.HtmlContent)); } } private static void DropTable(SQLiteConnection conn) { SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "Drop Table Question"; cmd.ExecuteNonQuery(); } }}
最後感謝萌萌的IT人:http://blog.csdn.net/dyllove98/article/details/9674137 ,我基本照抄這個部落格,然後去掉了後面暫時不用的模板部分。
如何在vs2012和2013中,為項目引入sqlite linq2db,以及C#操作sqlite的基本知識。