多くのグーグルで、さまざまなソースとアプローチをミキシングした後、これを実現する方法を見つけました。ここで最も重要なコードの抜粋です:
/// <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文を含むテキストボックス要素です。
はSystem.Data.SQLite.dllとそのがディレクティブを使用して対応への参照を追加することを忘れないでください。
私は不思議です - それを行うには何か問題はありますか? –
2時間無回答です。私は他の誰も*これをやっているとは思いません:-) – paxdiablo
こんにちは、SOは**マークアップ**を許可し始めました。コメントです。カッコいい! – paxdiablo