Reputation: 61
im trying to display a (For example): UserCode and Password that is already set in my MS Access Database for Delphi if there is any fix for this i would appreciate it.
this is part of my code that im using to obtain the infos and display them into a TLabels and in which it returns the error that i'm having..
with DataModule5 do
begin
// using the following code should display credentials from ms-access database to label text (TESTING)
ADOQuery1.SQL.Text := 'SELECT * FROM Credentials ' +
'WHERE (UserCode = :UserCode) ' +
'AND (Password = :Password) ' +
'AND (FirstName = :FirstName) ' +
'AND (LastName = :LastName) ' +
'AND (Age = :Age) ' +
'AND (Adminstrator = :Adminstrator) ';
MyAccountPage.UsernameDetail.Caption := ADOQuery1.FieldByName('UserCode').asString;
MyAccountPage.PasswordDetail.Caption := THashMD5.GetHashString(ADOQuery1.FieldByName('Password').AsString);
ADOQuery1.Open;
MyAccountPage.Show;
end;
and this is what i get when i try to access to "My Account" form:
PS: Not just "UserCode" that is not found, but even the remaining details (Password, FirstName.. etc)
Thanks for help in advance!
Upvotes: 0
Views: 812
Reputation: 12014
You are reading values from your ADOQuery before you fetched them
Change
MyAccountPage.UsernameDetail.Caption := ADOQuery1.FieldByName('UserCode').asString;
MyAccountPage.PasswordDetail.Caption := THashMD5.GetHashString(ADOQuery1.FieldByName('Password').AsString);
ADOQuery1.Open;
to this
ADOQuery1.Open;
MyAccountPage.UsernameDetail.Caption := ADOQuery1.FieldByName('UserCode').asString;
MyAccountPage.PasswordDetail.Caption := THashMD5.GetHashString(ADOQuery1.FieldByName('Password').AsString);
EDIT
But that is not the only problem with your code.
As suggested by whosrdaddy in the comments, your parameters are not set. Please read about how to use parameters here
Also, never store passwords in clear text in your database. Better store the hash of the password, you can concatinate it with the user code as suggested by fpiette in the comments
Upvotes: 2