假设我的数据库表中有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
}
}