【发布时间】:2014-01-20 11:02:57
【问题描述】:
我不知道如何将 SQLite 表中的列名存储到字符串列表中。 以下代码使用列名(以及其他内容)填充 dataGridView:
string sDatabasePath = DBPath();
SQLiteConnectionStringBuilder datasource = new SQLiteConnectionStringBuilder();
datasource.Add("Data Source", sDatabasePath);
datasource.Add("Version", "3");
datasource.Add("New", "False");
datasource.Add("Compress", "True");
using (SQLiteConnection connection = new SQLiteConnection(datasource.ConnectionString))
{
connection.Open(); //opens connection
SQLiteCommand getColumnNames = new SQLiteCommand("PRAGMA table_info('myTable');", connection);
SQLiteDataAdapter myAdapter = new SQLiteDataAdapter(getColumnNames);
DataSet myDataSet = new DataSet();
//myAdapter.Fill(myDataSet, "name");
this.dataGridView1.DataSource = myDataSet;
this.dataGridView1.DataMember = "name";
connection.Close();
}
【问题讨论】:
-
datagrid中添加的表名正常吗?
-
在数据网格中,我正确获取了列名(数据网格中的第一列称为名称,每行是我表中列的名称。数据网格中的第二列称为 cid,第三种类型,第四个 not_null 等)。
标签: c# sql sqlite datagridview