ASP.NET中MS Access DB的下拉列表

时间:2019-04-20 07:08:43

标签: asp.net ms-access ado.net oledb

我希望从供应商表中获得公司名称的下拉列表,如我的代码所示。该代码运行没有错误,但没有加载下拉列表。请任何人都可以提供解决方案。谢谢。

`

  protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
        conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\tunji\source\repos\WebApplication1\Northwind.mdb; Persist Security Info = False";

        conn.Open();
        cmd.Connection = conn;
        OleDbCommand cmd = new OleDbCommand();
        string query = "select * from Suppliers";
        cmd.CommandText = query;

        OleDbDataReader reader = cmd.ExecuteReader();
        while (reader.Read())

        {

            DropDownList1.Items.Add(reader["CompanyName"].ToString());

        }

    }

`

0 个答案:

没有答案