Problem using command at runtime : TUNIQUERY
Posted: Thu 16 Mar 2017 15:55
I have the following function that worked normal, now I'm having problems in the parameters, the query on a datamodule always returns empty.
The last parameter is of type string:
if I use :
Returns normal because the data exists in the database.
Remembering that I use this same statement in a separate unit, the more I create the query at execution time. And works normal. Now about the datamodule, my querys do not return any more data. USE OF DELPHI BERLIN 10.1 UP1 PROFESSIONAL
The last parameter is of type string:
Code: Select all
function TDM.RetornaStringTabela(CampoRetorno: string; tabela: string;
Campochave: string; ValorChave: string): string;
begin
Result := '';
if ValorChave = EmptyStr then
Exit;
try
try
QBusca.Close;
QBusca.SQL.Clear;
QBusca.SQL.Text := 'SELECT ' + CampoRetorno + ' FROM ' + TABELA +
' WHERE ' + CampoChave + ' = :cod';
[b] QBusca.ParamByName('cod').AsString := ValorChave; [/b]
QBusca.Prepare;
QBusca.Open;
if QBusca.RecordCount > 0 then
result := QBusca.fieldbyname(CampoRetorno).AsString;
except on E: Exception do
begin
QBusca.CancelarTransacao;
raise Exception.CreateFmt('Erro ao buscar campo %s da tabela %s ' +
sLineBreak+ E.Message, [CampoRetorno, TABELA]);
end;
end;
finally
QBusca.Close;
end;
end;
Code: Select all
QBusca.SQL.Text := 'SELECT ' + CampoRetorno + ' FROM ' + TABELA +
' WHERE ' + CampoChave + ' = ' + quotedStr(valorchave);
Remembering that I use this same statement in a separate unit, the more I create the query at execution time. And works normal. Now about the datamodule, my querys do not return any more data. USE OF DELPHI BERLIN 10.1 UP1 PROFESSIONAL