Click here to Skip to main content
15,919,479 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

Your database can generate the sequential IDs for you.

1) Create an ID column in your database (I am guessing you are using MS SQL because you stated only C#).
2) Set Identity column to true on the ID column
3) Set Autoincrement to true on the ID column

The ID column value will be created automatically based on existing items in the database and you will get a sequence 1,2,3,.. for your product IDs. This column can also become the primary key for your Students table.
 
Share this answer
 
Comments
mohit jain 21-Sep-12 6:27am    
Any Sample Code for reference
You should use IDENTITY[^] property of Transact-Sql to define an identity column for the table. You don't need to insert values in identity column. I'll automatically insert a running number in your table column.
Refer the links for example:
Identity Columns[^]
IDENTITY columns in SQL Server[^]


All the best.
--Amit
 
Share this answer
 
Comments
mohit jain 21-Sep-12 7:18am    
plz tell me clearly..
plz step by step
plz if u can....
_Amy 21-Sep-12 7:24am    
Create a table with IDENTITY column. Try,
CREATE TABLE tblTest(
ID INT IDENTITY,
Name VARCHAR(50) NOT NULL,
Address VARCHAR(150) NOT NULL
)

Insert the values to it, like:
INSERT INTO tblTest VALUES('Amit', '#142, Bangalore');
So you don't suppose to insert a value in identity column. The value for identity column will be inserted automatically like, 1, 2, 3, 4, 5 etc.

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