string connstring = "Provider=Microsoft.Jet.OleDb.4.0;";
connstring += @"Data Source=D:\DataAll\MEASUREMENT30.mdb";
OleDbConnection conn = new OleDbConnection(connstring);
conn.Open();
DataTable dt = conn.GetSchema("Tables");
//dataGridView1.DataSource = dt;//方便查看dt的內容
List tableNames = dt.Rows.OfType().Select(x => (string)x["Table_Name"]).ToList();
comboBox2.DataSource = tableNames;
comboBox2.Text = Convert.ToString(this.comboBox2.SelectedValue);
為什麼上面的語句沒有實現,選中combobox下拉中的選項時,顯示變為自己選的內容
如果是要取列table name裡的數據應該是這樣:
List<string> tableNames = dt.AsEnumerable().Select(p => p.Field<string>("Table_Name")).ToList();