代码之家  ›  专栏  ›  技术社区  ›  Michael Neale

是否有人在SharpDevelopment中使用System.Data.sqlite?

  •  2
  • Michael Neale  · 技术社区  · 5 年前

    我只是想知道你们中是否有人成功地整合了 数据库 变成一个 锐利发展 项目?如果是这样的话,如果你不介意继续和我们其他人分享这段经历,那将是非常有趣的。

    我试过用更正统的方法 Visual Studio 2008速成版 但是,尽管它显然很适合 Visual Web开发人员 ,不幸的是 平方网 包裹 fails 与之合作 视觉C 所以夏普发展是我现在唯一的希望。

    提前感谢大家。

    1 回复  |  直到 15 年前
        1
  •  3
  •   Nano Taboada    15 年前

    在大量搜索和混合各种来源和方法之后,我找到了一种方法来解决这个问题。下面是一段最重要的代码:

    /// <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);
    }
    

    在哪里? 结果数据标记视图 已使用IDE创建,并且 查询文本框 是包含SQL语句的文本框元素。

    不要忘记添加对的引用 system.data.sqlite.dll文件 及其对应的 使用 指令。