日期:2014-05-20  浏览次数:20476 次

谁能给我看看有什么问题
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 是数据库里的字段名 就不在外面加 ' '