在大量搜索和混合各种来源和方法之后,我找到了一种方法来解决这个问题。下面是一段最重要的代码:
/// <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文件
及其对应的
使用
指令。