什么是最好的方式来连接和使用C#中的SQLite数据库

我以前在C ++中通过包含sqlite.h来做到这一点,但在C#中有一个类似的简单方法吗?

SQLite的ADO.NET 2.0提供程序每天有超过200个下载,所以我认为你使用这个安全。

我和布鲁斯在一起。 我使用http://system.data.sqlite.org/也很成功。; 下面是我创build的一个简单的类示例:

using System; using System.Text; using System.Data; using System.Data.SQLite; namespace MySqlLite { class DataClass { private SQLiteConnection sqlite; public DataClass() { //This part killed me in the beginning. I was specifying "DataSource" //instead of "Data Source" sqlite = new SQLiteConnection("Data Source=/path/to/file.db"); } public DataTable selectQuery(string query) { SQLiteDataAdapter ad; DataTable dt = new DataTable(); try { SQLiteCommand cmd; sqlite.Open(); //Initiate connection to the db cmd = sqlite.CreateCommand(); cmd.CommandText = query; //set the passed query ad = new SQLiteDataAdapter(cmd); ad.Fill(dt); //fill the datasource } catch(SQLiteException ex) { //Add your exception code here. } sqlite.Close(); return dt; } } 

还有一个NuGet包:System.Data.SQLite可用。

我用这个很成功:

http://system.data.sqlite.org/

免费没有限制。

(来自评论的注释:原始站点不再存在,上面的链接有一个指向404站点的链接,并且包含原始站点的所有信息)

–Bruce

http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers有一个;.net的Sqlite包装列表。 从我听说http://sqlite.phxsoftware.com/是相当不错的。; 这个特定的一个让你像访问其他数据库一样通过ADO.Net访问Sqlite。

现在也有这个选项: http : //code.google.com/p/csharp-sqlite/ – C#的一个完整的SQLite端口。

在.NET Framework中使用SQLite数据库的另一种方法是使用Fluent-NHibernate
[它是包装在NHibernate中的NET模块(ORM模块 – 对象关系映射),允许以stream畅的模式编程(没有XML文件)configurationNHibernate。]

这里是简单的“入门”的说明如何在C#中一步一步做到这一点:

https://github.com/jagregory/fluent-nhibernate/wiki/Getting-started

它包含一个Visual Studio项目的源代码。

单声道来一个包装,使用他们的!

https://github.com/mono/mono/tree/master/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0提供的代码来包装实际的SQLite DLL( http://www.sqlite。 org / sqlite-shell-win32-x86-3071300.zip ,在下载页面http://www.sqlite.org/download.html/上find )以.net友好的方式。 它适用于Linux或Windows。

这似乎是最薄的世界,最大限度地减less你对第三方图书馆的依赖。 如果我必须从头开始这个项目,这是我会这样做的方式。