我是C#和Linq的新手,想要从MS Access中使用Linq填充ComboBox
。但是,如果我调试代码,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 :(得分:0)
谢谢,填充我的池 - 对象是问题所在。我通过添加.Fill():
得到它
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();
正在运行;)