asp.net 数据库读取值与用户输入值比较问题
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSys...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string getName;
string getPassword;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
String str = "Data Source=yanyan;Initial Catalog=Data;Integrated Security=True;Pooling=False";
SqlConnection coon = new SqlConnection(str);
//打开连接
coon.Open();
//读取数据
SqlCommand cmd = new SqlCommand("select * from UserInfo where Uname='" + UserNameLogin.Text + "'", coon); //创建查询用户名是否存在数据对象
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
getPassword = sdr["Upassword"].ToString();
if (getPassword == PasswordLogin.Text)//密码正确
{
Session["userID"] = UserNameLogin.Text.Trim();//存储用户名
Response.Redirect("SuccessLogin.aspx");
}
else
{
ErrorLable.Text = "密码错误";
ErrorLable.Visible = true;
}
//else
// LabErrorname.Visible = true;
}
coon.Close();
}
我给程序设置了断点,但他不走
if (getPassword == PasswordLogin.Text)//密码正确
{
Session["userID"] = UserNameLogin.Text.Trim();//存储用户名
Response.Redirect("SuccessLogin.aspx");
}
if里的这段代码,但是getpassword(从数据库里取出的值)的值是等于PasswordLogin.Text的
不知道是哪里错了 ,请帮忙看看,谢谢了 展开
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string getName;
string getPassword;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
String str = "Data Source=yanyan;Initial Catalog=Data;Integrated Security=True;Pooling=False";
SqlConnection coon = new SqlConnection(str);
//打开连接
coon.Open();
//读取数据
SqlCommand cmd = new SqlCommand("select * from UserInfo where Uname='" + UserNameLogin.Text + "'", coon); //创建查询用户名是否存在数据对象
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
getPassword = sdr["Upassword"].ToString();
if (getPassword == PasswordLogin.Text)//密码正确
{
Session["userID"] = UserNameLogin.Text.Trim();//存储用户名
Response.Redirect("SuccessLogin.aspx");
}
else
{
ErrorLable.Text = "密码错误";
ErrorLable.Visible = true;
}
//else
// LabErrorname.Visible = true;
}
coon.Close();
}
我给程序设置了断点,但他不走
if (getPassword == PasswordLogin.Text)//密码正确
{
Session["userID"] = UserNameLogin.Text.Trim();//存储用户名
Response.Redirect("SuccessLogin.aspx");
}
if里的这段代码,但是getpassword(从数据库里取出的值)的值是等于PasswordLogin.Text的
不知道是哪里错了 ,请帮忙看看,谢谢了 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询