The Infinite Loop – Beginner's SEO, Beginner C# & JQuery Tutorials Problem. Problem Solved. Loop. – The life of a programmer

14Aug/090

Creating/Retrieving a GUID object from a string C#

GUIDS are great to use if you ever may need to merge data.
The chances of collision (duplicates) are extremely low.

To generate a new guid, use this code:
Guid g=Guid.NewGuid(); //this generates a GUID object
Guid g2=Guid.NewGuid().ToString(); //this generates a GUID string





There may be a time where in a stored procedure, you have a GUID as a parameter.

In C# you may have to pass this paramater to the procedure.
This is actually very simple.

Given a string that you know is a GUID, you can retrieve a guid object like so:
Guid g=new Guid(myStringGUID);

And thats all folks :)

Filed under: C#, Programming, SQL No Comments