How to log into the system

Asked

Viewed 121 times

1

I’m new to Delphi and noticed that there is no use of variables as a date readers in this language as in VB. I am making a procedure to log into 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 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;

1 answer

4


After Execsql you should check for data as passed by parameter:

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

Anyway, I already answered a question a long time ago that might help you:

Login screen acting incoherent

  • Execsql does not open the dataset, it just executes the intro. In this case, it should be dmDados.query.open. Then, just test if the dataset is not empty (dmDados.query.Isempty).

  • note that it uses with dmDados.query do then only the IsEmpty it is necessary...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.