Ir para conteúdo
Fórum Script Brasil
  • 0

Pegar código em Insert


Heitor Glöckner

Pergunta

Olá, estou com um problema, tenho duas tabelas uma pedidos e outra pedidos_cliente construidas no access, e as duas são abertas para inserção ao mesmo tempo, e gostaria que a tabela pedidos_cliente armazenasse o código da tabela pedidos que é a chave primária, eu pensei em algo como "table.last" e somar um, porém se o usuário deletar o último registro, que é possível, vai pegar o valor incorreto do código, então gostaria de pegar direto o valor do código gerado no Insert da tabela de pedidos.

Obrigado !

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0
Olá, estou com um problema, tenho duas tabelas uma pedidos e outra pedidos_cliente construidas no access, e as duas são abertas para inserção ao mesmo tempo, e gostaria que a tabela pedidos_cliente armazenasse o código da tabela pedidos que é a chave primária, eu pensei em algo como "table.last" e somar um, porém se o usuário deletar o último registro, que é possível, vai pegar o valor incorreto do código, então gostaria de pegar direto o valor do código gerado no Insert da tabela de pedidos.

se voce estiver usando o componente ADO para conexão com o banco de dados veja no help do delphi

TCustomADODataSet.RecNo

Indicates ordinal position of the active record in the recordset.

Indica a posição ordinal do registro ativo no recordset.

property RecNo: Integer;

Description

Read RecNo at runtime to determine the ordinal position of the active record within the dataset’s recordset. The dataset must be active for RecNo to have a valid value. When a dataset component is active, RecNo will be a number between one and the total number of rows in the recordset (reflected in the RecordCount property).

The value of Recno for a given row in a recordset is relative to the rows that precede the current row. Thus, if a check of RecNo for a row indicates 10 and then a preceding row is deleted, a subsequent inspection of RecNo will show a new position of 9.

In the example below, the RecNo and RecordCount properties of a TCustomDataSet descendant are used to display the current record's number and the total number of records in a TStatusBar component. This would be done in a handler for the AfterScroll event of the ADO dataset component so that it is updated after each row pointer movement.

StatusBar1.Panels[0].Text := 'Record ' + IntToStr(TCustomADODataSet(DataSet).RecNo) + ' of ' + IntToStr(TCustomADODataSet(DataSet).RecordCount);

Set RecNo at runtime to move the record pointer to the record at the specified absolute position within the recordset. Use the value of the RecordCount property to determine the maximum number to which RecNo can be set. For example, going to the last row using RecNo:

ADOTable1.RecNo := ADOTable1.RecordCount;

Note: The number of rows indicated might be less than the total number of rows in a table. This can happen when the rows retrieved as a recordset for a dataset component are a conditional subset of the table.

abraço

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...