有两个asp.net的页面,第一个页面是一些条件,选择条件点击查询按钮,就跳转到第二个页面,第二个页面把满足上个页面所选的条件的信息显示出来。第一个页面的代码是这样的,我用的Session传的值 Session["fbsj"] = txtfbsj.Text;
Session["zldw"] = txtzldw.Text;
Session["zlr"] = txtzlr.Text;
Session["zlzt"] = ddlzlzt.SelectedValue;
Session["bt"] = txtbt.Text;
Session["fkqx"] = txtfkqx.Text;
Response.Redirect("YanPanSelectResult.aspx");请问第二个页面的查询语句要怎样写?这样写是错的:
SqlConnection con = SqlCon.GetSqlConnection();
SqlDataAdapter da = new SqlDataAdapter("select * from jh_zlxx where ((@fbsj is null or zlxx_fbsj=@fbsj) and (@zldw is null or zlxx_zldw=@zldw) and (@zlr is null or zlxx_zlr=@zlr) and (@zlzt is null or zlxx_zlzt=@zlzt))",con);
da.SelectCommand.Parameters.AddWithValue("@fbsj", Session["fbsj"]);
da.SelectCommand.Parameters.AddWithValue("@zldw",Session["zldw"]);
da.SelectCommand.Parameters.AddWithValue("@zlr",Session["zlr"]);
da.SelectCommand.Parameters.AddWithValue("@zlzt",Session["zlzt"]);
DataSet ds = new DataSet();
da.Fill(ds, "SelectResult"); gdvFaBu.DataSource = ds;
gdvFaBu.DataBind();
查询出来什么也没有。哪里错了啊??
Session["zldw"] = txtzldw.Text;
Session["zlr"] = txtzlr.Text;
Session["zlzt"] = ddlzlzt.SelectedValue;
Session["bt"] = txtbt.Text;
Session["fkqx"] = txtfkqx.Text;
Response.Redirect("YanPanSelectResult.aspx");请问第二个页面的查询语句要怎样写?这样写是错的:
SqlConnection con = SqlCon.GetSqlConnection();
SqlDataAdapter da = new SqlDataAdapter("select * from jh_zlxx where ((@fbsj is null or zlxx_fbsj=@fbsj) and (@zldw is null or zlxx_zldw=@zldw) and (@zlr is null or zlxx_zlr=@zlr) and (@zlzt is null or zlxx_zlzt=@zlzt))",con);
da.SelectCommand.Parameters.AddWithValue("@fbsj", Session["fbsj"]);
da.SelectCommand.Parameters.AddWithValue("@zldw",Session["zldw"]);
da.SelectCommand.Parameters.AddWithValue("@zlr",Session["zlr"]);
da.SelectCommand.Parameters.AddWithValue("@zlzt",Session["zlzt"]);
DataSet ds = new DataSet();
da.Fill(ds, "SelectResult"); gdvFaBu.DataSource = ds;
gdvFaBu.DataBind();
查询出来什么也没有。哪里错了啊??
Session["zldw"].ToString()
Session["zlr"].ToString()
Session["zlzt"].ToString()
报错可能是有的seesion释放了。
session 后加上 .ToString()
session后面加上.ToString()报这样的错:赋值号左边必须是变量、属性或索引器
当前seesion为空 所以才报错。
你吧所有seesion["XX"]赋值。在tostring就可以ile
有些字段赋的值是应该用'括起来的