RSS

How to Generate Unique ID using GUID in C#

We can Generate the Unique ID or number for our Web User as Member ID. And also we can update the unique records of the Database using GUID of the C#.

>> The GUID is used to Generate the unique id's. It is pronounced as goo'id - Globally unique identifier.

>> It is a 128-bit integer that can be used to uniquely identify something. You may store users or products in your database and you want somehow uniquely identify each row in the database. A common approach is to create a autoincrementing integer, another way would be to create a GUID for your products.

>> How to Create ID

- System.GUID class is used to create a Rand Id for members.

-> Using this bellow code we can create

System.Guid mid = Guid.NewGuid();
MessageBox.Show(mid.ToString());

or
 MessageBox.Show(System.Guid.NewGuid().ToString("P"));

Some of Formats: P, N, D,B
Ex.
MessageBox.Show("This is Test ID:" + System.Guid.NewGuid().ToString("P"));
MessageBox.Show("This is Test ID:" + System.Guid.NewGuid().ToString("D"));
MessageBox.Show("This is Test ID:" + System.Guid.NewGuid().ToString("B"));

0 comments:

Post a Comment