我使用此代码填充组合框但是可能在第2列ex1上的column1 ex:name处关联; ID?使用cmbbox.valuemember =
private DataTable BindData()
{
using (var conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\YOURDB.mdb; PersSecurity Info=False;")) /your connectionsting
{
using (var dAd = new OleDbDataAdapter("select column1 from Table ", conn)) //select query from your DB
{
var dSet = new DataTable();
try
{
conn.Open();
dAd.Fill(dSet);
return dSet;
}
catch
{
throw;
}
finally
{
if (conn.State == ConnectionState.Open) conn.Close();
}
}
}
}
buttonevent
var dt = BindData();
cmbBox.DataSource = dt;
cmbBox.DisplayMember = "column1"; //Display Table Column on your DB
答案 0 :(得分:2)
关于DisplayMember& Combobox的ValueMember属性,这可能会有所帮助: