当前位置: 代码迷 >> ASP.NET >> 哪位高手能给小弟我看看有什么有关问题
  详细解决方案

哪位高手能给小弟我看看有什么有关问题

热度:8059   发布时间:2013-02-26 00:00:00.0
谁能给我看看有什么问题
string   strConn   =   System.Configuration.ConfigurationManager.AppSettings[ "BuildMaterialConnectionStr "];
                SqlConnection   conn   =   new   SqlConnection(strConn);
                SqlDataAdapter   ada   =   new   SqlDataAdapter( "SELECT ' "   +   DropDownList1.SelectedItem.Text   +   " ',city_Id   FROM   city_Province ",   conn);

                DataSet   ds   =   new   DataSet();
                ada.Fill(ds);

                this.DropDownList2.DataSource   =   ds;
                this.DropDownList2.DataTextField   =   this.DropDownList1.SelectedItem.Text;
                this.DropDownList2.DataValueField   =   "city_Id ";
                this.DropDownList2.DataBind();

最后出问题在   this.DropDownList2.DataValueField   =   "city_Id ";说是找不到 "DropDownList1.SelectedItem.Text   "                    


------解决方案--------------------------------------------------------
SqlDataAdapter ada = new SqlDataAdapter( "SELECT " + DropDownList1.SelectedItem.Text + ",city_Id FROM city_Province ", conn);
如果 DropDownList1.SelectedItem.Text 是数据库里的字段名 就不在外面加 ' '
  相关解决方案