Problema Recuperar Ultimo ID MSSQL

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
decioneto2000
Posts: 3
Joined: Mon 07 Jul 2014 14:43

Problema Recuperar Ultimo ID MSSQL

Post by decioneto2000 » Mon 07 Jul 2014 14:49

Não consigo recuperar o Ultimo ID inserido no MSSQL com cached updata abilitado e campo id autoincremento usando master detail alguem ja conseguiu algo?


Thanks;

Decio

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Problema Recuperar Ultimo ID MSSQL

Post by Pinturiccio » Wed 09 Jul 2014 11:33

Please describe your scenario in more details. Please provide the following information:
1. DDL/DML scripts of the tables you use;
2. The sample of code that causes the issue. A test project will be appreciated. You can send us a test project by using the contact form on our website http://www.devart.com/company/contactform.html
3. Which behavior do you get?
4. Which behavior do you expect?

decioneto2000
Posts: 3
Joined: Mon 07 Jul 2014 14:43

Re: Problema Recuperar Ultimo ID MSSQL

Post by decioneto2000 » Thu 10 Jul 2014 15:15

Usando Uniquery Delphi 7 MSSQL 2012 uma simples select em uma tabela configurando os insert e update ligada a uma master detail porem quando se aplica o apply nao consigo retornoa ro id identity deo MSSQL


gratos

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Problema Recuperar Ultimo ID MSSQL

Post by azyk » Wed 16 Jul 2014 15:12

If you are using your own INSERT SQL query in the dataset, then to retrieve the inserted record ID, you should :
- set TUniQuery.Options.ReturnParams to True
- in the TUniQuery.BeforeUpdateExecute event specify explicitly the ptInputOutput parameter type for the Identity field

For example:

Code: Select all

DetailUniQuery.Options.ReturnParams := True;
...
procedure TForm1.DetailUniQueryBeforeUpdateExecute(Sender: TDataSet;
  StatementTypes: TStatementTypes; Params: TDAParams);
begin
  if StatementTypes = [stInsert] then
    Params.ParamByName('ID').ParamType := ptInputOutput;
end;

decioneto2000
Posts: 3
Joined: Mon 07 Jul 2014 14:43

Re: Problema Recuperar Ultimo ID MSSQL

Post by decioneto2000 » Wed 18 Apr 2018 18:45

Esse procedimento funciona com cached Update ativo?

]
Obrigado

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Problema Recuperar Ultimo ID MSSQL

Post by Stellar » Thu 19 Apr 2018 14:46

The above sample is just for updating the value of an auto-incremental or calculated field in dataset when using cached data updates.

Post Reply