我只是想知道你们中是否有人成功地将SQLite集成到SharpDevelop项目中?如果是这样的话,如果你不介意和我们一起分享经验的话,那就很有趣了。
我尝试过一种更传统的方法,使用Visual 2008速成版和诸如此类的东西,但是,尽管它显然与Visual Web Developer很好地合作,但不幸的是,SQlite.NET包失败与Visual C#一起工作,所以SharpDevelop是我现在唯一的希望。
提前谢谢大家。
发布于 2009-07-06 03:36:17
在谷歌大量搜索并混合了各种来源和方法之后,我找到了一种方法来解决这个问题。下面是最重要的代码片段:
/// <remarks>
/// Creating a DataSet to feed the DataGridView
/// </remarks>
//
DataSet results = new DataSet();
try
{
/// <remarks>
/// Setting the path where the database file is located
/// </remarks>
string database = "X:\\path\\to\\database\\file\\books.db";
/// <remarks>
/// Creating a ConnectionString pointing to the database file
/// </remarks>
SQLiteConnectionStringBuilder datasource = new SQLiteConnectionStringBuilder();
datasource.Add("Data Source", database);
datasource.Add("Version", "3");
datasource.Add("New", "False");
datasource.Add("Compress", "True");
/// <remarks>
/// Starting the connection and sending the query
/// </remarks>
using (SQLiteConnection connection = new SQLiteConnection(datasource.ConnectionString))
{
using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(queryTextBox.Text, connection))
{
/// <remarks>
/// Populating the DataGridView
/// </remarks>
adapter.Fill(results);
resultsDataGridView.DataSource = results.Tables[0].DefaultView;
}
}
}
catch (Exception error)
{
MessageBox.Show("Exception caught: " + error.Message);
}其中resultsDataGridView是用IDE创建的,queryTextBox是包含SQL语句的TextBox元素。
不要忘记使用System.Data.SQLite.dll指令添加对及其相应的引用。
https://stackoverflow.com/questions/1083187
复制相似问题