2

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

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

提前感谢大家。

4

1 回答 1

3

在谷歌搜索了很多并混合了各种来源和方法之后,我找到了一种方法来实现这一点。这是最重要的代码片段:

/// <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指令的引用。

于 2009-07-06T03:36:17.573 回答