经过谷歌搜索和混合各种来源和方法后,我找到了一种方法来实现这一点。这里有最显著代码片段:
/// <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及其相应的的引用。
我很好奇 - 有什么问题吗? – 2009-07-05 00:17:41