Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi can anyone give me an idea how to create an auto generated id like ED01,ED02 etc., so that when i am entering data the id should be automatically incremented
Posted

private static int EmpId = "ED00";

Form load

MIDL
visitCounter++;

   textBox1.Text = visitCounter;


This will automatically increment the vale but if you close the application again it will take from starting.
 
Share this answer
 
v2
Comments
anupama962010 30-Aug-10 4:28am    
i am a starter to be specific for sql server can u give me a more details about the answer you have give. thanks in advance
demouser743 30-Aug-10 4:30am    
from the code you can pass in that way.
demouser743 30-Aug-10 4:34am    
Can you please tell whether you want to auto increment the id itself in sql or you would like to display the auto generate id in your textbox and will pass to sql
anupama962010 30-Aug-10 6:44am    
i have textboxes which consists of id and name where, in id i need to display the auto generated code which is user defind(Ex01) and next to the last value in the database automatically and enter the name. then i have to save both in database.
example if i have ED05 record as last record in database then in the id textbox it should show ED06 & this field is not writable. then name is entered and both are stored in database so whenever when the next user sees the text box it should check database and then display ED07
SQL
create  TABLE ED(
  ID INTEGER PRIMARY KEY IDENTITY(1, 1)
  , UserID AS 'ED' + CAST(ID AS VARCHAR(32))
  , I INTEGER
)


DECLARE @I INTEGER
SET @I = 0
WHILE @I < 100
BEGIN
  SET @I = @I + 1
  INSERT INTO ED VALUES (@I)
END



Try this as per your requirement
 
Share this answer
 
SQL
CREATE



TABLE user(id INT NOT NULL IDENTITY(1,1),

col

AS 'ED'+

RIGHT(




'0'+CAST(id AS VARCHAR(2)),2))

INSERT



INTO userDEFAULT VALUES

SELECT




* FROM user
 
Share this answer
 

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