原来是美男哪里看免费:.net有一问题,高手看看?

来源:百度文库 编辑:中科新闻网 时间:2024/04/28 18:29:18
做了一个省市的级联,其中绑定到dropdownlist时出现错误
//绑定市
行 45: SqlCommand cmdcity=new SqlCommand("select * from city where proid="+this.DropDownList1.SelectedValue,con);
行 46: sdr=cmdcity.ExecuteReader();
行 47: this.DropDownList2.DataSource=sdr;
行 48: this.DropDownList2.DataTextField="cityname";
真是找不出来哪错了啊

值没有加单引号.
改成SqlCommand cmdcity=new SqlCommand("select * from city where proid='"+this.DropDownList1.SelectedValue+"'",con);
试试

看看this.DropDownList1.SelectedValue 值.如果你要是没有改动的话默认是this.DropDownList1.SelectedText的值....那就不是ID了..