我的程序如下,运行没有报错,但DropDownList2没有值,DropDownList1就绑定数据库的
.有没有高手给看一下
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ SqlConnection MyConnection;
MyConnection = new SqlConnection("server=(local); uid=sa; pwd=sa; database=mydb");
MyConnection.Open();
string sql = "select * from class1 where name = '" + DropDownList1.SelectedValue + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, MyConnection);
DataSet ds = new DataSet();
da.Fill(ds, "class1");
DropDownList2.DataSource = ds.Tables[0];
//在此传入sql语句,取得dataset
//this.DropDownList2.DataSource = ds;
this.DropDownList2.DataTextField = "id";
this.DropDownList2.DataValueField = "id";
this.DropDownList2.DataBind();
}
.有没有高手给看一下
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ SqlConnection MyConnection;
MyConnection = new SqlConnection("server=(local); uid=sa; pwd=sa; database=mydb");
MyConnection.Open();
string sql = "select * from class1 where name = '" + DropDownList1.SelectedValue + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, MyConnection);
DataSet ds = new DataSet();
da.Fill(ds, "class1");
DropDownList2.DataSource = ds.Tables[0];
//在此传入sql语句,取得dataset
//this.DropDownList2.DataSource = ds;
this.DropDownList2.DataTextField = "id";
this.DropDownList2.DataValueField = "id";
this.DropDownList2.DataBind();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货