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