1

I'm trying to code an object based on an SQL table, and up until this point, I've only dealt with strings/dates/int/long and so on, things that are relatively easily translatable to C#. I went to start coding my fields in c# for an asp page, and I noticed there is a unique identifier data type, and also an xml datatype. I am unsure as to how to proceed coding these datatypes into my fields, and how how to data will move inside of my project. Can anyone help shed some light on this, and possible get me started, at least with coding my object?

1
  • It sounds like you're talking about the SQL uniqueidentifier type. This corresponds conceptually to a System.Guid in .NET. I'm not sure the best way to convert between them. See also stackoverflow.com/questions/1435908/… Commented Apr 5, 2014 at 16:21

1 Answer 1

0

As @harpo said, a UNIQUEIDENTIFIER type in SQL is translated to a System.Guid in .NET. If you are using ado.net and a dataReader you can convert the column like so:

    Guid myUniqueIdentifier = reader["MyUniqueIdentifierColumn"] != DBNull.Value && reader["MyUniqueIdentifierColumn"] != null ? Guid.Parse(reader["MyUniqueIdentifierColumn"].ToString()) : Guid.Empty;

for an XML column you can just use a string dataType in c#. If you want to be able to get values from the XML then you need to create an object that mirrors the structure of the XML and deserialize the object using XmlSerializer or DataContractSerializer. For more information on that see this SO thread: https://stackoverflow.com/a/14723129/2488939

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.