0

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:

the error

PS: Not just "UserCode" that is not found, but even the remaining details (Password, FirstName.. etc)

Thanks for help in advance!

  • Hi, please check out the [documentation](http://docwiki.embarcadero.com/CodeExamples/en/ADOQuery_(Delphi)) how to work with parametrized queries. – whosrdaddy Apr 27 '21 at 06:50
  • @whosrdaddy yes i have tried to check that [documentaion](http://docwiki.embarcadero.com/CodeExamples/Sydney/en/ADOQuery_(Delphi)#Uses) out, but im stuck on the first `const ConnString...` where it says ADOConnection1 provider is SQLOLEDB.1 but my Provider is set to Microsoft.Jet.OLEDB.4.0 – Charles stealth Apr 28 '21 at 20:10
  • Just use your current connection string. The point I was trying to make is that you need to set a value for your parameters, which is explained in the docs (ADOQuery.Parameters.ParamByName) – whosrdaddy Apr 28 '21 at 20:12
  • @whosrdaddy i did use my current connection string but it gets me this error: "could not find installable ISAM" – Charles stealth Apr 28 '21 at 20:20
  • @whosrdaddy here is my "FormCreate" [full code](https://codeshare.io/GkkoB4) like in the documentaion. when i run that, i get the error code that i mentioned "Could not find installable ISAM" – Charles stealth Apr 28 '21 at 20:43

1 Answers1

2

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

GuidoG
  • 11,359
  • 6
  • 44
  • 79
  • 1
    I would add that storing password in clear text in a database is really a bad idea. It is much better to store a hash code of the password concatenated with the user code. – fpiette Apr 27 '21 at 06:37
  • 1
    2nd problem is that he is not setting the parameters... – whosrdaddy Apr 27 '21 at 06:49