Toon posts:

[ASP.NET] String.Equals() geeft onnodig false terug

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hi All,

Het gaat erom dat String.Equals(HashedTestPwd,MyDR.GetString(0)) false geeft terwijl de twee waarde die worden vergeleken wel degelijk aanwezig zijn en gelijk zijn (Ook van DataType).

Als ik een Response.Write doe direct na de String.Equals met de twee variabelen dan staan ze daar heel mooi bij, maar vergelijken homaar. 8)7 8)7


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
private bool validateUser(string id,string UnHashedPwd)
{
    // Make the Database Connection.
    const string ConnStr = "MyDataConnectionString;";
    SqlConnection MySqlConn = new SqlConnection(ConnStr);
    MySqlConn.Open();

    bool result=false;
    string HashedTestPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(UnHashedPwd, "md5");
            
    string SQL = "SELECT PassWord FROM UserInfo WHERE (LoginName = '"+TextBox1.Text+"')";
    SqlCommand MySqlCmd = new SqlCommand(SQL, MySqlConn);
    SqlDataReader MyDR = MySqlCmd.ExecuteReader();
            
    if (!MyDR.Read())
    {
        result=false;
        Label5.Text = "!MyDR.Read() returns true";
    }
    else
    {
        if (MyDR.IsDBNull(0))
        {
            result=false;
            Label5.Text = "MyDR.IsDBNull(0) Results in True";
        }
        else
        {
            result=(String.Equals(HashedTestPwd,MyDR.GetString(0)));
            Label5.Text = "String.Equals Results in True<br>" + HashedTestPwd + "<br>" + MyDR.GetString(0);
            Label5.Text += "<br>But the value is "+result;
        }
    }

    MyDR.Close();
    MySqlConn.Close();
    return result;
}


.modbreak: indenting iets minder gemaakt :)

[ Voor 11% gewijzigd door .oisyn op 21-10-2003 20:45 ]


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 12:02

.oisyn

Moderator Devschuur®

Demotivational Speaker

En output nu bijvoorbeeld eens quotes om de strings heen, of andere tekens, zodat je evt. de spaties voor of na de waarden kunt zien

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


Verwijderd

Topicstarter
.oisyn

Mag ik u hartelijk bedanken ...... _/-\o_
Er stond idd een spatie achter de MyDB.GetString(0). Soms zoeken naar een naald in een hooiberg.
Nu dus MyDB.GetString(0).Trim().

TOPPIE

[ Voor 11% gewijzigd door Verwijderd op 21-10-2003 21:41 ]