我是C#的新手,正在创建一个测试应用程序,用于从Access数据库中的表填充组合框。我希望能够即时设置此信息。作为测试人员,我创建了一个新表单,添加了一个名为“TBCallOutcome”的组合框,并添加了代码。
但是,它似乎在每行中填充了“System.Data.DataRowView”的下拉列表。
任何想法 - 谢谢你?
private void Form1_Load(object sender, EventArgs e)
{
string query = "SELECT [Call outcome] FROM [DD Call Outcomes] WHERE ((([Show on list])=True)) ORDER BY [Sort order]";
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='N:\\Test\\Dropdowns.mdb';User Id=admin; Password=;");
DataTable source = new DataTable();
dAdapter.Fill(source);
TBCallOutcome.DataSource = source;
}
答案 0 :(得分:-1)
您必须为DisplayMember
设置ComboBox
:
private void Form1_Load(object sender, EventArgs e)
{
string query = "SELECT [Call outcome] FROM [DD Call Outcomes] WHERE ((([Show on list])=True)) ORDER BY [Sort order]";
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='N:\\Test\\Dropdowns.mdb';User Id=admin; Password=;");
DataTable source = new DataTable();
dAdapter.Fill(source);
TBCallOutcome.ValueMember = "[Call outcome]";
TBCallOutcome.DisplayMember = "[Call outcome]";
TBCallOutcome.DataSource = source;
}