【发布时间】:2012-10-26 01:12:04
【问题描述】:
假设我的数据库表中有超过 300 个列,因为列 #3 之后的每个列都是相同的数据类型,有没有一种有效的方法可以从 SqlCeConnection/SqlCeDatabase 加载列?
private void loadDataGridView() {
String CmdString = "...... FROM MyDatabaseTable"; //some sql to get col info
SqlCeCommand cmd = new SqlCeCommand(CmdString, con);
SqlCeDataAdapter sda = new SqlCeDataAdapter(cmd);
DataTable dt = new DataTable("mastertable");
sda.Fill(dt);
foreach(Col col in dt) {
DataGridViewColumn c = new DataGridViewColumn(..); //Create the Col
c.DataPropertyName = col.Name; //Bind the col and property name
dataGridView1.Cols.Add(new dataGridViewColumn(...) ); //Add the col
}
}
【问题讨论】:
标签: c# winforms datagridview