Posts

Showing posts from 2015

How to use GUID in asp.net C# for unique ID?

Image
What is GUID ? GUID stands for Globally Unique IDentifier. It is a string of numbers and/or letters. A GUID represents a Unique identifier - means you cannot generate the same GUID more than once. A GUID has a very low (...practically impossible) probability of being duplicated  Here is a sample code of GUID use in asp.net c#.  Guid  newGuid =  Guid.NewGuid(); string query = "INSERT INTO tbl_info (UserID ,Username ,Emailaddress  ,Password  ,country)  VALUES                 (@UserID,@Username,@Emailaddress,@Password,@country)";         cmd.CommandText = query;         cmd.CommandType = CommandType.Text;         cmd.Connection = con;         cmd.Parameters.AddWithValue("@UserID",  newGuid  .ToString()); // GUID USE HERE         cmd.Parameters.AddWithValue("@Username", UNTextBo...

What is GUID ? How to generate a GUID ?

What is GUID ? GUID stands for Globally Unique IDentifier. It is a string of numbers and/or letters. A GUID represents a Unique identifier - means you cannot generate the same GUID more than once. A GUID has a very low (...practically impossible) probability of being duplicated  GUIDs have a variety of applications. You can use a GUID as a primary key in your database table or in a several other scenarios. A good example would be, if you have a distributed application where data is generated and stored in various locations and you want to merge all those data at some intervals of time, you may use GUID as the primary key. How to write a GUID in c#. GUID newguid = GUID.NewGuid(); // this will create a 36  characters  Outputs: 12345678-1234-1234-1234-123456789abc How to apply limit the length of GUID? string character= Guid.NewGuid().ToString().Substring(0, Guid.NewGuid().ToString().IndexOf("-")); this will generate a unique alpha numeric charct...