我有一个winform
带有access file
as 的项目database
。在我的一种形式中,我希望用户company
从combobox
.
(campanies 列表在访问表中)
如何将company name
列设置为组合框下拉值?
尝试这个
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();
去尼米
这是 oledb 命令吗?
我的解决方案是....
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();
}