0
My Sale table has a Code field with auto-increment and need to recover this code to insert in an associative table.
string sql = $"INSERT INTO VENDA(NRO_VENDA,DATA_VENDA,VALOR_TOTAL_PRODUTOS,VALOR_ACRESCIMO,VALOR_DESCONTO,VALOR_TOTAL_VENDA,CODIGO_CLIENTE)VALUES({entidade.nroVenda},'{entidade.DataVenda}',{entidade.ValorTotalProdutos},{entidade.ValorAcrescimo},{entidade.ValorDesconto},{entidade.ValorTotalVenda},{entidade.Cliente.Codigo})";
ConnectionFirebird.ExecComand(sql);
My table Venda
has the field Codigo
with auto-increment in which I want to recover that value.
Ref: looking for something like Mysql Last_insert_id
Post the excerpt of this code!?
– novic
last record? select using MAX(CODE) since it is auto increment
– TotallyUncool
I copied your comment to the body of the question.
– Victor Stafusa
@Totallyuncool, Using MAX() is not good practice. First, it does not guarantee that you will have the last record created, especially if it is a popular bank, following that if you have many records, it will be extremely time-consuming to return.
– Thiago Lunardi