Click here to Skip to main content
15,891,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using 3 Tier Architecture for insert the data into the database..
but my problem how to generate prod_id automatic without entering into textbox or label.
when page loads,it automatic change..
plz reply
Posted
Comments
Manash Sahoo 22-Sep-12 3:38am    
in which db u working on....if it is sql server then make ur prod_id identity,if u using mysql then make it autoincrement.....

I am not sure which database you are working on but all rdbms database has colum - Audo feature.

Like in Sql server, you can use int and set identity to true
Even you can declare the datatype as uniqueidentifier and while you insert use NewId() to generate unique identifier.

In the sql or stored procedure return the maxid() value to get the id ir use @@Identity for Auto.

If you want to do it manually, get the last id using max() function and increment the number by one and send it to database. But check the concurrent issue.

Hope this helps.

cheers
 
Share this answer
 
Create a store procedure and use this code to insert .it insert prod_id automatically



<pre lang="SQL">
create procedure sp_insert_products
declare @prod_id nvarchar

as

set @prod_id = ( select isnull( (max(cast( prod_id as int ))),0) + 1 from products )
begin
insert into tbl_products
values (your values goes here)
end
 
Share this answer
 
Comments
mohit jain 24-Sep-12 1:24am    
ALTER PROCEDURE AddRecords
(

@prod_id int,
@prod_title varchar(50),
@prod_qty varchar(50),
@prod_price varchar(50),
@prod_desc varchar(50),
@prod_imgpath varchar(50)

)

AS

insert into Products

(prod_id,prod_title,prod_qty,prod_price,prod_desc,prod_imgpath)

values

(@prod_id,@prod_title,@prod_qty,@prod_price,@prod_desc,@prod_imgpath)

RETURN

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