Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have been trying to generate ID's for a project I am doing. The user wants the ID's to starts with 'TKHC' than numerics like 001. Each time the form loads the auto-generated ID like TKHC001 should be loaded to the userID textbox.

What I have tried:

so far I have only been able to create a numeric ID
C#
private void TKHCI_UserID_Load()
        {
            var userID = DBS.TKHCI_Users.ToArray();
            ID = userID.LastOrDefault().TKHCI_id + 1;
            txtTKHCI_UserID.Text = Convert.ToString(ID);
        }


I need help to implement the requirement.
Posted
Updated 19-Jun-21 6:58am
Comments
PIEBALDconsult 19-Jun-21 11:47am    
Don't use alphanumeric values as IDs -- they're very inefficient.
If you are using SQL Server, please look into using a Sequence to reliably generate unique values -- particularly in a multi-user scenario.

Also, avoid using the Convert class, it does nothing that can't be done better another way (except for the ChangeType method).
All Convert.ToString(ID) will do is add complexity atop ID.ToString() and you gain nothing.
Member 14133069 19-Jun-21 11:56am    
Thank you for the comment however that is the user requirement. The user wants the ID's to start with TKHC then 001 ++

1 solution

txtTKHCI_UserID.Text = "TKHC" + Convert.ToString(ID);

?
 
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