How to use System.Guid.Parse within 3.5

I build my BLL with .Net Framework 4.0, but then I noticed that I need this for the WebServices application, so I changed the version of .Net to 3.5. Now I have this line of code giving me an error:

tmp.GlobalIdentifier = Guid.Parse(Convert.ToString(row["GlobalIdentifier"]));

Error

'System.Guid' does not contain a definition for 'Parse'

which is a very clear mistake. Do you have any equivalent “Analysis” method in any other class? What would be the best way to parse SQL Server UniqueIdentifier in a System.Guid object using .Net framework 3.5?

+6
source share
3 answers

try tmp.GlobalIdentifier = new Guid(Convert.ToString(row["GlobalIdentifier"]))

MSDN documentation binding

+17
source
 Guid myGuid = new Guid("B80D56EC-5899-459d-83B4-1AE0BB8418E4"); 
+4
source

What is the .NET type that is used to store SQL Server's unique identifier?

If it is an SqlGuid struct, you can simply use the provided explicit conversion operator :

 tmp.GlobalIdentifier = (Guid)(SqlGuid)row["GlobalIdentifier"]; 

If you are using a string that Guid can accept, then you can simply use the Guid constructor overload, which accepts the string, as others have mentioned.

+1
source

Source: https://habr.com/ru/post/897689/


All Articles