我有一个winform
项目,access file
为database
。
在我的某个表单中,我希望用户从company
中选择combobox
。
(公共场所列表在访问表中)
如何将company name
列设置为组合框下拉值?
答案 0 :(得分:0)
试试这个
string qr1 = "select companyname from table1";
SqlCommand cmd1 = new SqlCommand(qr1, con);
con.Open();
SqlDataReader dr1 = cmd1.ExecuteReader();
cmbcat.Items.Clear();
while (dr1.Read())
{
cmbcat.Items.Add(dr1[0].ToString());
}
con.Close();
答案 1 :(得分:-1)
到尼米
这是oledbcommand吗?
我的解决方案是......
public void make_cbDispatch()
{
string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;"
+ "Data Source=I:\\Projects\\project.accdb;"
+ "Persist Security Info=False;";
string qr1 = "SELECT DISTINCT object "
+ "FROM tList "
+ "ORDER BY object ";
OleDbConnection con = new OleDbConnection(ConnectionString);
OleDbCommand cmd1 = new OleDbCommand(qr1, con);
con.Open();
OleDbDataReader dr1 = cmd1.ExecuteReader();
cbDispatch.Items.Clear();
while (dr1.Read())
{
cbDispatch.Items.Add(dr1[0].ToString());
}
con.Close();
}