Reputation: 84
how to create unique id for each user in asp.net C#
I was used random number for each profile but its not unique.
Upvotes: 2
Views: 4022
Reputation: 705
If you’re using SQL Server (I’m pretty sure something similar exists in Oracle and MySQL but I can’t confirm) you can use identity column with integer value that will automatically generate unique ID for new user.
If you need something different like you shown in one of the comments “INMHPU123333” then you’ll need to create a separate function for this.
Note that this is not really ideal from the performance perspective because it will cause big index fragmentation. Not a huge deal though if you don’t have large number of records.
Upvotes: 1
Reputation: 62260
Guid.NewGuid() is almost unique.
Guid id = Guid.NewGuid();
// Output: e62e2706-a8db-4fae-891a-65985fd80351
Upvotes: 3