日期:2014-05-18 浏览次数:20617 次
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnectionString"]); //创建连接对象
SqlCommand cmd = new SqlCommand("select * from Users where userId='" + txtUserName.Text + "'", conn); //创建查询用户名是否存在数据对象
try
{
conn.Open(); //打开连接
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read()) //如果用户名输入正确
{
if (sdr["userPwd"].ToString() == txtPassword.Text)//密码正确
{
conn.Close();
Session["userID"] = txtUserName.Text.Trim();//存储用户名
Response.Redirect("AddressList.aspx"); //进入系统
}
else
{
Response.Write("<script language=javascript>alert('您输入的密码错误!')</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('您输入的用户名错误或该用户名不存在!')</script>");
}
------解决方案--------------------
最简单的就是在第一个页面的cs代码里
string name=this.TextBox.Text;
Session["form1"] = name;
Response.Redirect("default2.aspx");
然后在default2的页面
string username=Session["form1"];
就可以得到第一个页面textbox里面的值
------解决方案--------------------
if(Session["userID"] !=null)
{
this.lbl.Text=Session["userID"] ;
}
------解决方案--------------------