Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am trying to add ID in text box. it should be auto-generated & Alphanumaric.
I have written below code & its working for taking next id but when table has some records it automatically take last id from table & then increment by one and ID format should be LEL5-1,LEL5-2,LEL5-3....so on.


C#
static int EJDS_id = 1;
        string code;

 private void JDF_Load(object sender, EventArgs e)
        {
            
            EJDS_id = EJDS_id + 1;
            txtjobno.Text = "LEL5-" + EJDS_id.ToString();
                     

        }


Please help
Posted
Updated 14-Jan-16 20:18pm
v3
Comments
yourfriendaks 15-Jan-16 2:23am    
is your database column set to Auto Increment or you are inserting value(Auto incremented value) to column?
Member 12265496 15-Jan-16 2:54am    
I am inserting the auto incremented value in a textbox.its auto incremented & Alphanumaric
Member 12265496 21-Jan-16 7:08am    
yes
BillWoodruff 15-Jan-16 2:44am    
Your code does what you say it does; so something else must be changing the value of 'EJDS_id .... if that value does not appear "correct" ... something like calls to the 'JDF_Load method you are not aware of.

Put a break-point in the 'JDF_Load method and single-step through the code when you the break-point ... observing how it is called.

Are you "exporting" the 'EJDS_id variable by reference anywhere else in the code ?
Member 12265496 15-Jan-16 2:55am    
Yes correct My code changing the value of EJDS Id but I will take last id from table then increment by one.

 
Share this answer
 
Comments
BillWoodruff 15-Jan-16 11:29am    
+5
Peter Leow 15-Jan-16 20:18pm    
Thank you, BillWoodruff.
Maciej Los 15-Jan-16 17:31pm    
5ed!
Peter Leow 15-Jan-16 20:18pm    
Thank you, Maciej.
If your database column is auto increment value inserted by you Eg. LEL5-1,LEL5-2,LEL5-3 and so on. Then Read the record from database split it with character '-' and store nuber value to array and sort to desc and read the 1st value from top.It will be Highest ID value .Now increment with one , show the value to text box with your format.
 
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