0

I am creating a multi-user application based on SQL server and VB.NET I am adding new row to table and then query to get the new id because its auto generated

insert in transactions

and then I get the new ID in anther query

select Top 1 transaction_ID from Transactions .....

and use this id to insert rows in anther table called TransactionDetails

this is safe in single user application. but in multiuser application I might get the wrong transaction_ID if anther user add anther transaction.

What is the best way to handle that? Thank you,

  • Isn't there an equivalent to `last_insert_id` that would be returned from your `insert` query? Does this link help: https://stackoverflow.com/questions/5228780/how-to-get-last-inserted-id – droopsnoot Sep 18 '19 at 09:07
  • Thank you so much. I found it in your link – Ayman Mustafa Sep 21 '19 at 09:44

1 Answers1

0

I tried that and it works

SQL="insert into transactions() values() SELECT SCOPE_IDENTITY()"

dim LastID as integer =command.ExecuteScalar(SQL)