How to log in delphi system

1

I am new to Delphi and noticed that there is no presence of use of variables like date readers in this language as in VB. I am making a procedure to login to the system. The connection to the bank is already ready and functional my doubt is:

How to proceed with reading data in the database now?

Follow the code with the connection to the bank:

procedure TFrmPrincipal.GetConnection();
var
  diretorioDb: String;
begin
  diretorioDb := ExtractFilePath(ParamStr(0));

  if FileExists(diretorioDb + 'DataBase.mdb') then
  begin
    if dmDados.bdConnection.Connected = false then
    begin
      dmDados.bdConnection.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Psddword="";Data Source=' + diretorioDb + 'DataBase.mdbde Seu programa';
      dbDados.bdConnection.Connected        := true;
    end
    else
    begin
      dmDados.bdConnection.Connected := false;
    end;
  end
  else
  begin
    ShowMessage('Banco de Dados não Encontrado!');
  end;
end;

Login method:

procedure TfrmLogin.LogarSistema(userPr: string; senhaPr: string);
begin
  with dmDados.query do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT * FROM usuarios WHERE username =userPr and senha =senhaPr');

    Parameters.ParamByName('userPr').Value  := userPr;
    Parameters.ParamByName('senhaPr').Value := senhaPr;

    ExecSQL;
  end;
  showmessage('Logado Com Sucesso!');
end;
    
asked by anonymous 03.09.2016 / 19:28

1 answer

4

After ExecSQL you should check if data exists as per parameter:

if (dmDados.IsEmpty = False) then
begin
  ShowMessage('Logado com Sucesso');
end
else
begin
  ShowMessage('Senha incorreta, ou usuário inexistente');
end;

Anyway, I've already answered a question that may help you:

login screen acting incoherently

    
05.09.2016 / 19:14