views:

1096

answers:

1

I was just wondering if perhaps any of you guys has been successful integrating SQLite into a SharpDevelop project? If that's the case it'd be really interesting if you wouldn't mind to go ahead and share the experience with the rest of us.

I've tried the more sort of orthodox approach of using Visual Studio 2008 Express Editions and whatnot but, although it apparently plays well with Visual Web Developer, unfortunately the SQlite.NET package fails to work with Visual C#, so SharpDevelop is pretty much my only hope now.

Thanks everyone in advance.

A: 

After googling a lot and mixing a variety of sources and approaches I've found a way to acomplish this. Here's a snippet of most significant code:

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

Where resultsDataGridView has been created with the IDE and queryTextBox is a TextBox element containing the SQL statement.

Don't forget to add a reference to System.Data.SQLite.dll and its corresponding using directive.

Nano Taboada