2017-02-18 85 views
0

我是C#和Linq的新手,並希望用來自MS Access的Linq填充ComboBox。但是,如果我調試代碼,ComboBox是空的。用MS Access中的Linq填充ComboBox

我讀了一些舊帖子,但他們沒有幫助。失敗在哪裏?

private void Form1_Load(object sender, EventArgs e) 
{ 
    try 
    { 
     connection.Open(); 
     label1.Text = "OK"; 

     PoolDataSet pool = new PoolDataSet(); 

     comboBoxPool.DisplayMember = "Pool-Name"; 
     comboBoxPool.ValueMember = "ID"; 

     comboBoxPool.DataSource = (from x in pool.Pools 
             select x._Pool_Name).ToList(); 

     connection.Close(); 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show("Error" + ex); 
    } 
} 
+0

移動的'comboBoxPool.DisplayMember = 「池名稱」

connection.Open(); connectionLabel.Text = "Connection successful!"; PoolsDataSet pool = new PoolsDataSet(); (new PoolsDataSetTableAdapters.PoolsTableAdapter()).Fill(pool.Pools); comboBoxPool.DataSource = (from x in pool.Pools select x.ID).ToList(); comboBoxPool.DisplayMember = "ID"; connection.Close();

它的運行; comboBoxPool.ValueMember =「ID」;'在這行下面:'comboBoxPool.DataSource'。 –

+0

然後,我收到了「無法綁定到新顯示成員」的例外... – prografix

+0

您是剪切並粘貼那兩行還是隻複製它們? –

回答

0

謝謝,填寫我的池 - 對象是問題。我.fill僞加入()得到它:;)