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