2009-07-04 43 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及其相應的的引用。

相關問題