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;
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).
– Ricardo Alves Carvalho
note that it uses
with dmDados.query do
then only theIsEmpty
it is necessary...– Junior Moreira