急!急!关于Session取值传值的问题!
问题是这样的
连接数据库登录后用Session保存用户名,然后在另一页面现实该用户名
代码如下 初学者请各位帮帮忙
这段代码是登录验证代码 问题我已经用文字说明
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MBConnectionString"].ConnectionString);
string sql = "select * from dbo.zhuce where zhanghao=@zhanghao and mima=@mima";
SqlDataAdapter adpt = new SqlDataAdapter(sql,con);
adpt.SelectCommand.Parameters.AddWithValue("@zhanghao",TextBox1.Text);
adpt.SelectCommand.Parameters.AddWithValue("@mima",TextBox2.Text);
DataSet ds = new DataSet();
adpt.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Session["zhanghua"] = TextBox1.Text.Trim();
这是我自己写的不知道对不对 我是想保存帐号
Response.Redirect("~/Default2.aspx");
Response.Write("OK");
}
else
{
Response.Write("NO");
}
}
接下来的是另一个页面 是取上面代码的帐号
protected void Page_Load(object sender, EventArgs e)
{
if(Session["zhanghao"]!=null)
{
Label2.Text+= "<b>[" + Session["zhanghao"].ToString() + "]</b>";
这也是我自己写了 可是运行之后 label2还是label2没有显示出上面页面的登录名
}
}
如果可以 请直接在我代码上做修改 注释一下谢谢
希望大家帮忙 小第先谢了