public DataTable selectcat(int catid)
{
SqlConnection con = new SqlConnection(DBHelper.connection);
SqlCommand com = new SqlCommand();
com.Connection = con;
con.Open();
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "selectcatalog";
com.Parameters.AddWithValue("@catid", catid);
SqlDataReader dr = com.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
con.Close();
return dt;
}
然后我在下拉列表事件(SelectedIndexChanged)中调用该函数
protected void catselectddl_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dt;
DAcatagory obj = new DAcatagory();
dt = obj.selectcat(catselectddl.SelectedValue);
DataRow dr = dt.Rows[0];
catnametxt.Text = dr["catname"].ToString();
catdestxt.Text = dr["catdescription"].ToString();
}
但它在dt = obj.selectcat(catselectddl.SelectedValue);
PS 处给了我无效的参数错误:下拉列表显示他的显示和数据库中的值