D
D
DimaDel2018-03-09 18:58:43
Delphi
DimaDel, 2018-03-09 18:58:43

How to check if a user exists in Access database?

DataModule2.ADOQuery1.SQL.Clear;
  DataModule2.ADOQuery1.SQL.Add('SELECT Password FROM Users WHERE login ='+#39+Edit1.Text+#39);
  DataModule2.ADOQuery1.Open;
  if DataModule2.ADOQuery1.IsEmpty then
    ShowMessage('Пользователь не найден!')
  else
    if DataModule2.ADOQuery1.FieldByName('Password').Value <> Edit2.Text then
      ShowMessage('Неверный пароль!')
    else
      begin
        Form1.Hide;
        Form3.Show;
      end;

Wrote a code that should check if the user exists and logs into the account, if yes. But for some reason, I enter the correct data, and it says to me that there is no user. What does it have to do with the record, starting with 2 in the database. If you log in to the admin account, which is the first entry, then everything is fine

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kalapanga, 2018-03-09
@kalapanga

You've generated a lot of questions. Now it is not clear whether you succeeded in inserting the record or not? Judging by this issue, you are inserting something wrong into the database. In my opinion, you have some kind of confusion with apostrophes there. Take a look at the database file with an access! See for yourself what is in this table, most likely not what you expect.

T
Timofey Mikhailov, 2018-03-20
@JimmiJanger

And if you write something like:

DataModule2.ADOQuery1.SQL.Add('SELECT Password FROM Users WHERE login ='+#39+Edit1.Text+#39);
  DataModule2.ADOQuery1.Open;
<b>ShowMessage(DataModule2.ADOQuery1.SQL.Text);</b>
  if DataModule2.ADOQuery1.IsEmpty then
    ShowMessage('Пользователь не найден!')
  else

What will he give you?
Maybe instead of #39 use QuotedStr ?
And maybe instead of the equal symbol, use "Like"?
SELECT * FROM table WHERE name LIKE 'Timmi'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question