Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I had two text boxes in frond end which is productname and No.of.batches...For example I selected a product 'X' and No.of batches as 10..It will get 10 rows and user will insert the data when user clicks submit it will reflect in database too...My requirement is generate an ID automatically PER transaction...I had to get an unique ID for the whole operation...what should i do to get that?

What I have tried:

C#
How do i get an unique ID per transaction which has multiple insertions
Posted
Updated 6-Dec-16 10:02am
Comments
OriginalGriff 3-Dec-16 2:57am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps if your show us via sample data, and indicate exactly what ID or IDs you are trying to get, and where?
Use the "Improve question" widget to edit your question and provide better information.
Tomas Takac 3-Dec-16 8:17am    
What kind of id? You can use NEWID function[^] to create a GUID.
jaket-cp 5-Dec-16 10:28am    
you may want to look at IDENTITY (Property) (Transact-SQL)
https://msdn.microsoft.com/en-us/library/ms186775.aspx

1 solution

If you want to do it entirely in SqlServer SQL, you merely need to set up your table with a column of the type uniqueidentifier, make it not null, and define the default value as

newsequentialid()

Then each time you insert a row, it will determine the id for that row automatically.

Good Luck
Brent
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900