[求大神]帮忙看看为什么运行出来不管输入的用户名正确与否,都是显示"用户名或者密码错误,请重新输入!"没办法实现成功登录的效果

LEHUIC LEHUIC 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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>");

}


}


}
...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
LEHUIC
.NET社区 62,273 成员 668,968 内容