MIGRAR FUNÇÃO DO ADO PARA O FIREDAC
24/09/2020
0
Boa tarde! sempre trabalhei com o ADO para fazer as conexoes e consultas, porem preciso migrar agora para o Firedac e não esto conseguindo converter essa minha função... alguem pode me ajudar?
e chamo ela da seguinte maneira
Function GetSQL(Tipo, sSql: String): TADOQuery; var Query: TADOQuery; begin try Query := TADOQuery.Create(Application); Query.ConnectionString :='' //minha string de conexão Query.Prepared := True; with Query do begin SQL.Clear; SQL.Add(sSql); if (Tipo = ''I'') or (Tipo = ''A'') or (Tipo = ''U'') then begin ExecSQL; SQL.Free; end else begin Open; end; Result := Query; end; except on E: Exception do begin ShowMessage(''Erro na Consulta SQL : '' + E.Message); Result := nil; end; end; end;
e chamo ela da seguinte maneira
GetSQL(''S'', ''SELECT * FROM TABELA'');
Hamdem Voguel
Curtir tópico
+ 0
Responder
Posts
24/09/2020
Emerson Nascimento
tente algo assim:
Function GetSQL(Tipo, sSql: String): TFDQuery; var Query: TFDQuery; begin Result := nil; try Query := TFDQuery.Create(Application); Query.Connection := DM.FDConnection; //uma instância de um FDConnection //se não houver uma instância pública, passe uma por parâmetro with Query do begin SQL.Text := sSql; if (Tipo = 'S') then Open else begin ExecSQL; SQL.Text := ''; end; Result := Query; end; except on E: Exception do ShowMessage('Erro na Consulta SQL : ' + E.Message); end; end;
Responder
Clique aqui para fazer login e interagir na Comunidade :)