Search code examples
asp.netauto-generateuserid

How to generate UserID as created with new user registration?


I have a normal database and not using any membership provider and I would like to auto-generate a new user ID which is created in database with a new user registration.

As seen below this is what I need.

enter image description here


Solution

  • That is a GUID (in .net) or uniqueidentifier (in SQL).

    If you are using Microsoft SQL Server you can execute the following T-SQL:

    DECLARE @ID uniqueidentifier;
    SET @ID = NEWID();
    

    ...and then execute your INSERT statement.

    If you prefer to generate the ID in VB.NET you can use the following code:

    Dim id as Guid = Guid.NewGuid()