本帖最后由 张振鹏 于 2011-11-21 13:04 编辑
在做根据省份查询相应的市时,运行时省份的下拉列表却没有数据,- private void cbPromary_SelectedIndexChanged(object sender, EventArgs e)
- {
-
- using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLExpress;
- AttachDbFilename=|DataDirectory|\DBpromary.mdf;Integrated Security=True;User Instance=True"))
- {
- conn.Open();
- using (SqlCommand cmd = conn.CreateCommand())
- {
- cmd.CommandText = "select * from promary";
- using (SqlDataReader reader = cmd.ExecuteReader())
- {
- SqlDataAdapter adp = new SqlDataAdapter();
- adp.SelectCommand = cmd;
- DataSet ds = new DataSet();
- adp.Fill(ds, "customers");
- cbPromary.DataSource = ds.Tables["customers"];
- cbPromary.DisplayMember = "proName";
- cbPromary.ValueMember = "proName";
- //cbPromary.SelectedIndex = 0;
- }
- }
- }
- }
复制代码 我感觉数据连接没有建立,请各位指点一下,那里出现错误!应该如何绑定数据??? |