在一个页面调用数据库登陆后跳转到用户信息页面,使用label和TextBox显示用户在数据库中的信息

登录页面botton代码如下:

libraryDataContext xx = new libraryDataContext();
            string a = this.DropDownList2.SelectedValue;
                var q = from n in xx.VipReader
                        where n.姓名 == TextBox2.Text && n.密码 == TextBox3.Text
                        select n;
                if (q.Count() == 1)
                {
                    Response.Write("<script>alert('登录成功!');location='用户/用户信息.aspx'</script>");
                    HttpCookie cookie = new HttpCookie("name");
                    //写出name的内容
                    cookie.Value = TextBox3.Text;
                    //Expires是指过期时间=DateTime.Now.AddDays(1)是指它的过期的日期为当前日期再加上一天
                    cookie.Expires = DateTime.Now.AddDays(1);
                    //这段代码才真正的写到客户端当中
                    Response.Cookies.Add(cookie);


                }
                else
                {
                    Response.Write("<script>alert('登录失败!用户名或密码错误!');location='首页.aspx'</script>");


                }



跳转至用户信息页面后代码如下:

public partial class 用户信息 : System.Web.UI.Page
    {
        string ConString = ConfigurationManager.ConnectionStrings["library"].ConnectionString.ToString();
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBox1.Text = Request.Cookies["name"].Value;
                SqlConnection con = new SqlConnection(ConString);
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "select 姓名 from VipReader where 密码 = 'TextBox1.Text'";
                SqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                string a = reader.GetString(0);
                con.Close();
                Label10.Text = a;
            }
            
        }

    }

但是


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值