gpt4 book ai didi

.net - 有人在 SharpDevelop 中使用 System.Data.SQLite 吗?

转载 作者:搜寻专家 更新时间:2023-10-30 20:22:22 25 4
gpt4 key购买 nike

我只是想知道你们中是否有人成功地将 SQLite 集成到 SharpDevelop 项目中?如果是这样的话,如果您不介意继续与我们其他人分享经验,那将非常有趣。

我已经尝试过使用 Visual Studio 2008 Express Editions 等更正统的方法,但是,虽然它显然与 Visual Web Developer 配合得很好,但不幸的是SQlite.NET fails 使用 Visual C#,所以 SharpDevelop 几乎是我现在唯一的希望。

提前谢谢大家。

最佳答案

经过大量谷歌搜索并混合使用各种来源和方法后,我找到了一种方法来完成此任务。这是最重要的代码片段:

/// <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 及其相应的 using 指令的引用。

关于.net - 有人在 SharpDevelop 中使用 System.Data.SQLite 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1083187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com