我已經在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