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

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", UNTextBox.Text);
        cmd.Parameters.AddWithValue("@Emailaddress", EmailTextBox.Text);
        cmd.Parameters.AddWithValue("@Password", PasswordTextBox.Text);
        cmd.Parameters.AddWithValue("@country", CountryDropDownList.SelectedValue);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Write("Registration successfull");


OUTPUT OF USER ID



Comments

Popular posts from this blog

Handle and show SQL Exception show in popup message box in SAP ABAP

How to access an internal table of one program in another program