Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
hi, friend i have one table in that i would like add id like 00001,00002,00003..etc..how to get max value from database and how write code for increment ...? please help me...



my code is :
C#
sqlcon.Open();

     string strgvid = "select max(udid) from tbl_apply";
     SqlCommand cmdgvid = new SqlCommand(strgvid, sqlcon);
     int uid = Convert.ToInt32(cmdgvid.ExecuteScalar());
     lbl_uid.Text = Convert.ToString(uid);
     sqlcon.Close();
Posted

Instead of using Convert.ToString, just use ToString with a format indicator:
C#
lbl_uid.Text = uid.ToString("D5");
 
Share this answer
 
Use below Query.

SQL
CREATE TABLE [dbo].[EmployeeMaster](
  [ID] [int] IDENTITY(1,1) NOT NULL,
  [PreFix] [varchar](50) NOT NULL,
  [EmployeeNo]  AS ([PreFix]+ RIGHT('00000' + CAST(Id AS VARCHAR(7)), 7)) PERSISTED,
  [EmployeeName] VARCHAR(50)
)


for more details please follow below link.
C# Corner : Error Display[^]


Regards,
AARIF SHAIKH
 
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