string name = User_Name.Text;
            string password = User_Pwd.Text;
             conn = new SqlConnection(str);      string SQL = "select count(*) from User(表名) where UserName='" + name + "'and  PassWord='" + password + "'";
                           
               conn.Open();
                comm = new SqlCommand(SQL, conn);
                int sum = (int)(comm.ExecuteNonQuery());
                if (sum > 0)
                {
                    Session["Admin"] = name;
                    Response.Write("<script>alert('登陆成功');location.href='mang.aspx'<script>");
上面是用户登陆的判断语句!
执行后,提示SQL语法错误?我看了半天,没有发现错误啊!请问错在哪?

解决方案 »

  1.   


    string strSQL = "select count(*) from [User](表名) where UserName='" + name + "' and PassWord='" + password + "'";
      

  2.   

    select count(*) from User(表名) where UserName='" + name + "'and PassWord='" + password + "'
    返回的是首行首列。不应该用:ExecuteNonQuery。应该使用:ExecuteScalar()
    呵呵
      

  3.   

     string SQL = "select count(*) from [User](表名) where UserName='" + name + "'and PassWord='" + password + "'";
    因为User是特殊的字段
      

  4.   

    ExecuteNonQuery
    主要是用在update 和insert 等无返回值的语句。