注册 登录
编程论坛 ASP.NET技术论坛

语法错误 看看

即使你在 发布于 2016-11-14 10:40, 3204 次点击
protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (txtUsername.Text == "" || txtPassword.Text == "")
        {
            Response.Write("<script language=javascript>alert('用户名或密码不得为空!');</script>");
            return;
        }
        string connsql = System.Configuration.ConfigurationManager.AppSettings["connstring"];
        SqlConnection conn = new SqlConnection(connsql);
        conn.Open();
        string strSql = "select * from users where User_id=sa'" + txtUsername.Text + "'and User_password=123456'" + txtPassword.Text + "'";
        SqlCommand com = new SqlCommand(strSql,conn);
       SqlDataReader dr = com.ExecuteReader();
        if (dr.Read())
        {
            Session["User_id"] = dr["User_id"];
            Session["user_lever"] = dr["User_lever"];
2 回复
#2
苹果的种子2016-11-18 15:55
回复 楼主 即使你在
你的sql语句用户名是sa什么什么吗
#3
向洪林2016-11-18 21:02
string strSql = "select * from users where User_id=sa'" + txtUsername.Text + "'and User_password=123456'" + txtPassword.Text + "'";这句写法有错吧
试试string strSql = "select * from users where User_id='" + txtUsername.Text + "'and User_password='" + txtPassword.Text + "'";
1