我已经在C++中通过包含sqlite.h来完成此操作,但在C#中有类似的简单方法吗?连接和使用C#中的sqlite数据库的最佳方式是什么?
回答
ADO.NET 2.0 Provider for SQLite每天有超过200次下载,所以我认为你是安全的使用那一个。
有一个.net的Sqlite包装列表,在http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers。从我听到的http://sqlite.phxsoftware.com/是相当不错的。这个特定的一个可以让你像通过其他数据库一样通过ADO.Net访问Sqlite。
我已经取得了巨大成功使用此:
http://system.data.sqlite.org/
免费,没有任何限制。
(从审核注:原站点不再存在上面的链接有指向404网站的链接,并具有原始的所有信息。)
--Bruce
现在这个还有选项:http://code.google.com/p/csharp-sqlite/ - SQLite到C#的完整端口。
我与布鲁斯。我使用http://system.data.sqlite.org/也很成功。这是我创建的一个简单的类示例:
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;
}
}
单声道带有包装,使用它们!
https://github.com/mono/mono/tree/master/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0给出的代码以.net友好的方式包装实际的SQLite dll(http://www.sqlite.org/sqlite-shell-win32-x86-3071300.zip在下载页http://www.sqlite.org/download.html/上找到)。它适用于Linux或Windows。
这似乎是所有世界中最薄的一种,最大限度地减少了对第三方库的依赖。如果我必须从头开始这个项目,这是我会这样做的方式。
在.NET Framework中使用SQLite数据库的另一种方法是使用Fluent-NHibernate。
[这是一个包含NHibernate(ORM模块 - 对象关系映射)的NET模块,并允许以流畅模式编程(无XML文件)配置NHibernate。]
这是“入门”一步地做到这一点在C#中的步骤:
https://github.com/jagregory/fluent-nhibernate/wiki/Getting-started
它包括源代码作为Visual Studio项目。
https://github.com/praeclarum/sqlite-net现在可能是最好的选择。
- 1. 在c#中连接数据库的最佳方式是什么?
- 2. 连接android和oracle数据库的最佳方式是什么?
- 3. 在C#中处理多个数据库连接的最佳方式是什么
- 4. 在php中连接数据库的最佳方法是什么?
- 5. 处理SQLite数据库的最佳方式是什么?
- 6. 什么是我通过C#连接到离线数据库的最佳方式
- 7. 使用C++连接数据库的标准方式是什么?
- 8. 什么是使用Delphi的Web数据库的最佳方式?
- 9. 将iphone应用连接到mysql数据库的最佳方式是什么?
- 10. 在Java代码中查找数据库连接的最佳方式是什么?
- 11. 在Delphi中连接到Mysql数据库的最佳方式是什么
- 12. 什么是使用钛创建数据库的最佳方式
- 13. Sqlite数据库连接最佳实践
- 14. 什么是配置与MvvmCross和SQLite插件连接的最佳方式
- 15. 什么是给derby数据库连接字符串的最佳方式?
- 16. 确保数据库连接字符串的最佳方式是什么?
- 17. C:连接字符串的最佳和最快方式是什么
- 18. IPC连接Qt4和Qt5过程的最佳方式是什么?
- 19. 什么是处理从C#连接到MySql的最佳方式是什么?
- 20. 用PHP搜索MySQL数据库的最佳方式是什么?
- 21. 在Rails中建立数据库的最佳方式是什么?
- 22. 连接到SQL数据库的最佳实践是什么?
- 23. 什么是最佳的数据库连接策略
- 24. 用c访问YouTube数据api的最佳方式是什么?
- 25. 连接有序数组的最佳方式是什么?
- 26. 什么是在C++中追加数据的最佳方式
- 27. 最佳/正确的方式来存储SQLite数据源连接
- 28. 接口C#和Java的最佳方式是什么?
- 29. 什么是使用symfony2中的前端库的最佳方式
- 30. 在Silverlight中使用数据库的daba的最佳方式是什么?RIA
这是这个问题的重复:http://stackoverflow.com/questions/93654/is-there-a-netc-wrapper-for-sqlite并有不同的答案。 – 2008-09-24 14:47:20
可能的重复[是否有SQLite的.NET/C#包装?](https://stackoverflow.com/questions/93654/is-there-a-net-c-wrapper-for-sqlite) – Flimzy 2017-07-17 09:26:05