0

我有一个winform带有access fileas 的项目database。在我的一种形式中,我希望用户companycombobox.

(campanies 列表在访问表中)

如何将company name列设置为组合框下拉值?

4

2 回答 2

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();
于 2013-09-12T05:19:26.453 回答
-1

去尼米

这是 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();

}
于 2017-03-28T03:24:02.677 回答