GUID Datatype in .NET Schemas (How to save a GUID into a database)

Trying to save a simple dataset to a database but i keep getting the error
'Invalid Cast from System.String to System.Guid' when I try a DataAdapter.Update.

The dataset contains a GUID column...but the datatype in the dataset SCHEMA is a string.  What datatype should I be using? How does one ever save a GUID into a database ?

P.S I do not need to generate a new GUID.  I have a preset one I am using for now.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

.Net treats GUID as String anyway, so you would be better of to keep GUID as string (varchar, char) in Database. That will save you from unnecessary Conversion each time you retrieve or save GUID.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Actually there is a GUID data type in SQL Server 2000 (if that's what you're using). SqlDbType.UniqueIndentifier corresponds to the uniqueidentifier data type in SQL Server, so if you use that, you won't need to cast it. OleDbType also has a GUID data type called OleDbType.Guid, but you would have to find out if your database has a GUID data type, too.
alternatively, if you are saving the data to a STring data type in the Database, use this:

Dim MyGiud as Guid = New Guid
Dim strGuid as String = MyGuid.ToString

That is you can convewrt a Guid value to the Corresponding strin using ther .ToString method of the variable.

you can also convert a string (that hods a GUID value) to a GUID with:

Dim MyGuid as Guid = Guid(strGuid)  at least I think that is the syntax.  I do not have .NET installed at home, so I can't check it directly.

GUIDs are treated as GUIDs, Strings are treated as Strings.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.