在Microsoft Visual Studio 2010做登陆页面,但是代码运行时一直显示用户登陆失败
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.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Common;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string yhm = yhming.Text;
string yhumi = yhmi.Text;
if (yhming.Text == "" || yhmi.Text == "")
{
Response.Write("<script>alert('请输入用户名或密码!')</script>");
}
else
{
string sql = ConfigurationManager.ConnectionStrings["SPConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(sql);
conn.Open();
string sqlstr = "select * from T_User where UName=@UName and Password=@Password";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
SqlParameter para1 = new SqlParameter("@UName", yhm);
cmd.Parameters.Add(para1);
SqlParameter para2 = new SqlParameter("@Password", yhumi);
cmd.Parameters.Add(para2);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
Response.Redirect("index.html");
}
else
{
Response.Write("<script>alert('用户名和密码输入错误');</script>");
}
}
}
} 展开
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Common;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string yhm = yhming.Text;
string yhumi = yhmi.Text;
if (yhming.Text == "" || yhmi.Text == "")
{
Response.Write("<script>alert('请输入用户名或密码!')</script>");
}
else
{
string sql = ConfigurationManager.ConnectionStrings["SPConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(sql);
conn.Open();
string sqlstr = "select * from T_User where UName=@UName and Password=@Password";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
SqlParameter para1 = new SqlParameter("@UName", yhm);
cmd.Parameters.Add(para1);
SqlParameter para2 = new SqlParameter("@Password", yhumi);
cmd.Parameters.Add(para2);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
Response.Redirect("index.html");
}
else
{
Response.Write("<script>alert('用户名和密码输入错误');</script>");
}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询