[求大神]帮忙看看为什么运行出来不管输入的用户名正确与否,都是显示"用户名或者密码错误,请重新输入!"没办法实现成功登录的效果
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void btn_login_Click(object sender, EventArgs e)
{
string constr =@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|宠物商城.mdf;Integrated Security=True;User Instance=True";
conn.ConnectionString = constr;
conn.Open();
cmd.Connection=conn;
cmd.CommandText = "select * from 用户表 where 用户名='" + username.Text + "' and 密码='" + password.Text + "'";
try
{
da.SelectCommand=cmd;
da.Fill(ds,"用户表");
if (ds.Tables[0].Rows.Count==0)
{"用户名或者密码错误,请重新输入!";
Labino.Text =
username.Focus();
}
else
{
Labino.Text = "恭喜您登陆成功!";
Session["Admin_UserName"] = this.username.Text;
Response.Redirect("~/home.htm");
}
conn.Close();
}
catch (Exception ex)
{
Response.Write("<script >alert('系统错误:" + ex.Message + "!');</script>");
}
}
}
{
protected void Page_Load(object sender, EventArgs e)
{
}
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void btn_login_Click(object sender, EventArgs e)
{
string constr =@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|宠物商城.mdf;Integrated Security=True;User Instance=True";
conn.ConnectionString = constr;
conn.Open();
cmd.Connection=conn;
cmd.CommandText = "select * from 用户表 where 用户名='" + username.Text + "' and 密码='" + password.Text + "'";
try
{
da.SelectCommand=cmd;
da.Fill(ds,"用户表");
if (ds.Tables[0].Rows.Count==0)
{"用户名或者密码错误,请重新输入!";
Labino.Text =
username.Focus();
}
else
{
Labino.Text = "恭喜您登陆成功!";
Session["Admin_UserName"] = this.username.Text;
Response.Redirect("~/home.htm");
}
conn.Close();
}
catch (Exception ex)
{
Response.Write("<script >alert('系统错误:" + ex.Message + "!');</script>");
}
}
}
...全文
相关推荐
js实现指定用户名和密码登录
显示错误信息 document.getElementById('message').innerText = '用户名或密码错误,请重新输入!'
js判断用户名密码实现登录
('用户名或密码错误,请重试'); }}```以上代码只是一个简单的示例,实际应用中,通常会涉及到更复杂的验证规则,如密码强度检查、用户名存在性验证等。
JSP登陆验证 实现JSP用户名 密码 验证码验证登陆
本项目着重于实现一个JSP登录系统,包括用户名、密码以及验证码的验证功能。以下是关于这个项目的关键知识点:1.
python实现用户名密码校验
Python 实现用户名密码校验是常见的身份验证场景,在网络应用、简单脚本或者小型系统中广泛应用。以下是对这个主题的详细解析:首先,我们需要实现一个简单的登录系统,它包括以下几个核心功能:1.
JavaScript判断用户名和密码不能为空的实现代码
最后,如果`errMsg`仍然为空,即没有发现任何错误,那么就提交表单。否则,通过`alert`弹窗显示错误消息,并重新聚焦到出错的输入字段。


