Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using 3 tier architecture for using insert update delete operations..
i want to generate number for prod_id in insert operation.
plz reply anyone
Posted
Updated 19-Sep-12 23:35pm
v2
Comments
Sergey Alexandrovich Kryukov 21-Sep-12 0:37am    
Not a question. Not clear what's the problem.
--SA

Generating unique IDs in this context is the job of the database. You shouldn't be trying to manually create the prod_id value

You haven't mentioned what database you are using, I'm going to assume SQL Server.

* You probably have a 'Products' table or something like that. If prod_id is the unique identifier (primary key), then set the column to have the IDENTITY specification. Every time you insert into the table now, SQL Server will automatically generate the next available ID

* After inserting into the table, you can access the value that was generated by SQL by using the SCOPE_IDENTITY() function (are you using raw ADO.net? or an ORM like Entity Framework?)
 
Share this answer
 
Comments
mohit jain 20-Sep-12 6:59am    
not understand..
Dylan Morley 20-Sep-12 7:12am    
Identity columns - http://msdn.microsoft.com/en-us/library/ms186775.aspx

Scope Identity - http://msdn.microsoft.com/en-us/library/ms190315.aspx
this is a great artical will helps you click here
http://www.dotnetfunda.com/articles/article71.aspx[^]
 
Share this answer
 
v2
Comments
[no name] 20-Sep-12 5:44am    
great on my 5+
[no name] 20-Sep-12 5:46am    
5+
Kuthuparakkal 20-Sep-12 6:54am    
5+
[no name] 20-Sep-12 7:02am    
again thanx Kuthuparakkal sir
you can do this by two way

1 ) store your prod_id in global class and increment it by one before insert

2 ) pass your all data(without prod_id ) to database and after that find max existing prod_id from database and increment there in procedure

although first method is work fine but i prefer second method more.
 
Share this answer
 
Comments
mohit jain 20-Sep-12 5:40am    
how to store prod_id in global class..
any sample code..
Dylan Morley 20-Sep-12 6:35am    
Both of these options are just awful

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