日期:2014-05-18  浏览次数:20502 次

登录用户系统问题。为什么Red返回总是为0~求救啊
C# code
if ((this.usertxt.Text == "") || (this.pwdtxt.Text == ""))
        {
            Response.Write("<script>alert('用户名、密码不能为空');</script>");
        }
        else
        {
            string ConnectionString = "server=localhost;database=user;uid=sa;pwd=123456";
            SqlConnection con = new SqlConnection(ConnectionString);
            con.Open();
            string name = this.usertxt.Text.ToString();
            string pass = this.pwdtxt.Text.ToString();
            string cmdtxt = "select * from vip where user='" + name  + "' and pwd ='" + pass + " '";
            
            SqlCommand cmd = new SqlCommand(cmdtxt, con);
            int red = Convert.ToInt32(cmd.ExecuteScalar());
            if (red > 0)
            {
                Session["admin_name"] = this.usertxt.Text.ToString();
                Response.Redirect("hello.aspx");
            }
            else
            {
                Response.Write("<script>alert('请与管理员联系!');</script>");

            }
        }


------解决方案--------------------
探讨

引用:

引用:
...and pwd ='" + pass + " '";
看看有什么不同
...and pwd ='" + pass + "'";

不是这问题~我调试运行到SqlCommand cmd = new SqlCommand(cmdtxt, con);的时候,局部变量出现
cmd {System……

------解决方案--------------------
探讨

引用:
引用:

引用:
...and pwd ='" + pass + " '";
看看有什么不同
...and pwd ='" + pass + "'";

不是这问题~我调试运行到SqlCommand cmd = new SqlCommand(cmdtxt, con)……