如何在DataGridView中显示Sqlite的结果。
需 using System.Data.SQLite;
//数据库文件路径
var path1 = "d:\\temp\\temp.db";
System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();
connstr.DataSource = path1;
//建立数据库连接
System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();
conn.ConnectionString = connstr.ToString();
conn.Open();
//查询语句
string sqlCommandString = "select * from Friends";
//利用 Adapter 转换结果到 datagrid
SQLiteDataAdapter adapter = new SQLiteDataAdapter(sqlCommandString, conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
//关闭连接,并把结果显示在datagrid上
conn.Close();
conn.Dispose();
dataGridView1.DataSource = dv;