Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-24
5
Medium Priority
?
898 Views
Last Modified: 2008-02-07
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.
0
Comment
Question by:invisiblekid
5 Comments
 
LVL 18

Accepted Solution

by:
tusharashah earned 1500 total points
ID: 12393683
.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.

-tushar
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 12394380
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.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12394406
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.

AW
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12394446
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.

AW
0
 
LVL 3

Expert Comment

by:nitrogenx
ID: 12397224
GUIDs are treated as GUIDs, Strings are treated as Strings.  
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Loops Section Overview
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question