public static bool isCanLogin(SqlConnection Conn, string uname, string pwd)
    {
        //SqlCommand thisComm = new SqlCommand("select * from user ", Conn);
        SqlCommand thisComm = new SqlCommand("select user_name,user_pwd from UserLogin  where user_id=@name and user_pwd=@pwd", Conn);
        thisComm.Parameters.Add(new SqlParameter("@name", SqlDbType.Char, 50)).Value = uname;
        thisComm.Parameters.Add(new SqlParameter("@pwd", SqlDbType.Char, 50)).Value = pwd;
        SqlDataReader thisReader = thisComm.ExecuteReader();
        if (thisReader.Read())        {
            return true;
        }
        else
        {
            return false;
        }
    }断点在if (thisReader.Read())发生错误
错误提示
将 varchar 值 'admin                                             ' 转换为数据类型为 int 的列时发生语法错误。不明白什么意思,麻烦高手帮忙解答

解决方案 »

  1.   

    public static bool isCanLogin(SqlConnection Conn, string uname, string pwd)
        {
            //SqlCommand thisComm = new SqlCommand("select * from user ", Conn);
            SqlCommand thisComm = new SqlCommand("select user_name,user_pwd from UserLogin  where user_id=@name and user_pwd=@pwd", Conn);
            thisComm.Parameters.Add(new SqlParameter("@name", SqlDbType.Char, 50)).Value = uname;
            thisComm.Parameters.Add(new SqlParameter("@pwd", SqlDbType.Char, 50)).Value = pwd;
            SqlDataReader thisReader = thisComm.ExecuteReader();
            if (thisReader.HasRows)        {    //如果没有Select出了数据,thisReader.Read就出错了.
                return true;
            }
            else
            {
                return false;
            }
        }
      

  2.   

    你肯定数据库UeerLogin的user_name字段是字符型?thisComm.Parameters.Add(new SqlParameter("@name", SqlDbType.Char, 50)).Value = uname;
    thisComm.Parameters.Add(new SqlParameter("@pwd", SqlDbType.Char, 50)).Value = pwd;改成thisComm.Parameters.AddWithValue("name", uname);
    thisComm.Parameters.AddWithValue("pwd", pwd);试试.
      

  3.   

    应该是数据类型出错了.
    thisComm.Parameters.AddWithValue("name", uname); 
    thisComm.Parameters.AddWithValue("pwd", pwd); 
      

  4.   


    user_name,user_pwd from UserLogin  where user_id=@name and user_pwd=@pwd
    改成
    user_name,user_pwd from UserLogin  where user_name=@name and user_pwd=@pwd很明显,你把用户名的字段写成了自增的主键字段,一个是字符串,一个是整型变量.当然要报错了.如果你是做的登陆系统,你就得让用户名等于用户名嘛.
      

  5.   

    一般都是类型出错了~~或者是sql写错了