2009-07-04 44 views
2

我只是想知道你们中的任何一个人是否已经成功地将SQLite整合到SharpDevelop项目中?如果是这样的话,如果你不介意继续与我们其他人分享经验,那将会非常有趣。是否有人在SharpDevelop中使用System.Data.SQLite?

我试过那种更使用的Visual Studio 2008 Express版和诸如此类的东西,但正统的做法,虽然它显然与的Visual Web Developer,可惜SQlite.NETfails打得很好与Visual C#一起工作,所以SharpDevelop几乎是我现在唯一的希望。

谢谢大家提前。

+0

我很好奇 - 有什么问题吗? – 2009-07-05 00:17:41

回答

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

相关问题