what is the data types I get from the database by SqlDataReader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lucoin
    New Member
    • Sep 2007
    • 24

    what is the data types I get from the database by SqlDataReader

    I am using asp.net(C#) to build a login sys. I use the SqlDataReader to get the data from the data base to validate the user. but it always comes the password dosn't matches. but I tested to print the password get from the database and user input on the page, they are the same. can any one tell me why?

    I use text box to get user input
    like sting userpwd = textbox.text..T oString().Trim( );

    and SqlDataReader sdr = cmd.ExecuteRead er();
    .......
    if(str["Password"]==userpwd){}
    .......
    in the database, the password type is char(16)
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Are you making sure to cast the str["Password"] object as a string?
    Because if it's still referenced as an object, then it will do an object compare against the string (which would be false) and not a string comparison.

    Comment

    • lucoin
      New Member
      • Sep 2007
      • 24

      #3
      Originally posted by Plater
      Are you making sure to cast the str["Password"] object as a string?
      Because if it's still referenced as an object, then it will do an object compare against the string (which would be false) and not a string comparison.


      Thanks. That's the problem.

      I forgot to add .Trim();

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Plater
        Are you making sure to cast the str["Password"] object as a string?
        Because if it's still referenced as an object, then it will do an object compare against the string (which would be false) and not a string comparison.
        Actaully the == operator has the effect of calling ToString on the object so that == is done against two Strings. Thus for

        [CODE=cpp]object o = "object";
        string s = "object";[/CODE]
        s == o returns true.

        @OP calling Trim for password comparisons is rather odd. What if I want a password that ends with two spaces? I suggest you investigate where the extra spaces are coming from and solve that.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Originally posted by r035198x
          Actaully the == operator has the effect of calling ToString on the object so that == is done against two Strings.
          Learn something new everyday.

          Comment

          Working...