我不确定我在这里做错了什么。
我没有收到实际错误,但每次都返回 false:
string commandString =
"SELECT * FROM UserTable WHERE Username = @UserName";
DataTable result = new DataTable();
using (SqlCommand command = new SqlCommand(commandString, dataConnection))
{
command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = info.username;
using (SqlDataReader dr = command.ExecuteReader())
{
result.Load(dr);
}
}
if (result.Rows.Count > 0)
{
Console.WriteLine((string)result.Rows[0]["Password"]);
Console.WriteLine((string)result.Rows[0]["Username"]);
Console.WriteLine(info.password);
Console.WriteLine(info.username);
string dbPassword = (string)result.Rows[0]["Password"];
if (string.Compare(dbPassword, info.password) == 0)
return true;
else return false;
}
else
return false;