新建项目后,在程序包管理控制台中输入:
Install-Package linq2db.SQLite
回车。
下图中是之前翻&墙安装过(顺便赞1下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 ,我基本照抄这个博客,然后去掉了后面暂时不用的模板部份。