Retrieve guid from DB error: "Guid should contain 32 digits with 4 dashes"

In my database, I have a table with a uniqueidentifer field as the primary key.  I'm using SQL Server 2005.

------------------------------------------------------------------
MyTable
------------------------------------------------------------------
MyGuid  |  MyEmail  |  MyName
------------------------------------------------------------------

Given an email (a string), I'm trying to return the guid associated with that email.  I'm using LINQ to do this.  Here's my function:

public static Guid GetGuidFromEmail(string Email)
{
    MyDBDataContext db = new MyDBDataContext();

    var guid = from u in db.MyTable
               where u.MyEmail == Email
               select u.MyGuid;
        
    Guid g = new Guid(guid.ToString());
    return g;
}
 

The error occurs on the line where I create my guid.  It says:

System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

 

But there is nothing wrong with my guid.  This is the actual guid I'm testing with and there is nothing wrong with it:

ed4765a7-661a-451d-849a-d6f9655536f1

0
Apples
3/12/2009 6:12:01 PM
asp.net.getting-started 91979 articles. 2 followers. Follow

1 Replies
452 Views

Similar Articles

[PageSpeed] 4

Try this 

var guid = (from u in db.MyTable
    where u.MyEmail == Email
    select u.MyGuid).SingleOrDefault();
or an even more condensed version
public static Guid GetGuidFromEmail(string Email)
{
    MyDBDataContext db = new MyDBDataContext();
    return new Guid(db.MyTable.Single(g => g.MyEmail.Equals(Email)).MyGuid.ToString());
}
 

- William

Please mark the most helpful reply/replies as "Answer".

Give some of my PWSK modules a try.
0
whighfield
3/12/2009 11:52:29 PM
Reply:

Similar Artilces:

Error when trying to insert a Guid into a database "Failed to convert parameter value from a String to a Guid."
Hi there, I know the error tells everything but I cant seem to fix my problem. This is my code, when I try run it I get the above error. What do I need to change?   Any help would be great! private void InsertImages(string StoredProcedure, string UserID) { //Connect to stored procedure //Create a DataAdapter, and then provide the name of the stored procedure. SqlDataAdapter MyDataAdapter = new SqlDataAdapter(StoredProcedure, MyConnection);   //Set the command type as StoredProcedure. MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure; //Create and add...

Get "Mail"/"Get "News" / "Write"/"Post" buttons?
If the "Get Mail" button text changed to "Get News", and "Write" changed to "Post" when TB's in the news-reading mode, it would save me and probably others from constantly forgetting to make the change before proceeding. :-) Or is there an extension to do this which I don't know about? Thanks! Bob Bob P wrote: > If the "Get Mail" button text changed to "Get News", and "Write" > changed to "Post" when TB's in the news-reading mode, it would save me > and probably others...

VS.NET 2005 is ignoring in web.config strict="true". I get no error when I try this: Dim x As Integer = "string"
Hello,I have this in my VS.NET 2005 web.config <compilation debug="true" strict="true" explicit="true">When I do this in my vb code:Dim x As Integer = "string"I get no error. When I hit compilation I also get no error. What am I doing wrong?Thanks for helping!Regards,J. Bauer It's a bug of some sort See this response by Scott Guthriehttp://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=3c1c9898-8076-4f69-a5e2-e99573d03c6e Unfortunately we don’t have a GUI based way to configure this. L It is something we will make sure gets added back in, though, with the next...

Services don't start automatically ("Database cannot be started -- I/O error" or "Database cannot be started -- No such file or directory")
My situation is: ..server: Windows Server 2003 Standard Edition SP2 ..database server : Adaptive Server Anywhere 8.0.2.4372. Windows starts automatically 32 services ASA, one database in each service If I start each service in manual everything is ok. When I restart the server, four service (always four!!!) don't start correctly with two kind of error: "Database cannot be started -- I/O error" "Database cannot be started -- No such file or directory" The services that don't start are not the same. I tried many times and everytime the problem is on...

What is "guid"
Hi, what is "guid"? I have seen it several times talking about create a guid, but I do not know what it is and what it is used for. Thanks GUID stands for Global Unique Identifier, and is essentialy a 128 bit number that is suppose to be unique no matter what. you can use tools like GUIDgen or uuidgen that comes with VS to generate one, or you can simply use System.GUID class. One common representation they use for GUID's is something like: {9B0EFD60-F7B0-11D0-BAEF-00C04FC308C9} GUID stands for Globally Unique Identifier. GUIDS can be created with uuidgen.exe, CoCr...

Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
Hi All, I am getting above sometimes.I am inserting values in three tables Company,Merchant and users at a time.Guid is kept as primary key(uniqueidenitifier).Why this error is coming i am unable to find it is happening sometimes.Any idea to rectify it ??   Regards How are you generating the GUID?  C# code or are you having the database generate it? Database is generating it. Hi Brijesh Singh, How did you go about inserting the values into the three tables? Usually, you will receive this exception in these scenarios: In Microsoft SQL Server Management Studio, y...

Getting "Problem in Mapping Fragment starting at line ..." error when trying to create table mappings for table associations in ADO.NET Entity Framework
 Table A: COUNTRY_LOOKUP COUNTRY_ID   smallintclustered, unique, primary key located on PRIMARY    COUNTRY_ID TABLE B: COUNTRY_MODE_RULES CARRIER_ID    intMODE_RULE_TYPE_ID    intORIG_COUNTRY_ID    smallintDEST_COUNTRY_ID    smallint clustered, unique, primary key located on PRIMARY    CARRIER_ID, MODE_RULE_TYPE_ID, ORIG_COUNTRY_ID, DEST_COUNTRY_IDThere is a foreign key relationship from COUNTRY_MODE_RULES to COUNTRY_LOOKUPORIG_COUNTRY_IDREFERENCES .COUNTRY_LOOKUP (COUNTRY_ID)DEST_CO...

superreview cancelled: [Bug 90918] RFE: Add url in "comments" field of the "get info" window when download file. : [Attachment 182858] Patch ver. 4, correcting error
Torben <torben@despammed.com> has cancelled Torben <torben@despammed.com>'s request for superreview: Bug 90918: RFE: Add url in "comments" field of the "get info" window when download file. https://bugzilla.mozilla.org/show_bug.cgi?id=90918 Attachment 182858: Patch ver. 4, correcting error https://bugzilla.mozilla.org/attachment.cgi?id=182858&action=edit ...

superreview requested: [Bug 90918] RFE: Add url in "comments" field of the "get info" window when download file. : [Attachment 182858] Patch ver. 4, correcting error
Torben <torben@despammed.com> has asked Simon Fraser <sfraser_bugs@smfr.org> for superreview: Bug 90918: RFE: Add url in "comments" field of the "get info" window when download file. https://bugzilla.mozilla.org/show_bug.cgi?id=90918 Attachment 182858: Patch ver. 4, correcting error https://bugzilla.mozilla.org/attachment.cgi?id=182858&action=edit ------- Additional Comments from Torben <torben@despammed.com> asking sfraser for sr and doug for r/sr? for the LocalFile2 change. ...

Installation Guide is weak. Has a "no Worry FYI" but not "how to install"
Name: Ari V Email: defygravity79atyahoodotcom Product: Thunderbird Summary: Installation Guide is weak. Has a "no Worry FYI" but not "how to install" Comments: read / review it for yourself. Browser Details: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11 ...

Getting "No error" instead of "No such file or directory" on Win32
Hi all, in this CPAN testers XML-LibXML test failure: http://www.cpantesters.org/cpan/report/d9cf95fc-d5e8-1017-8e8a-88a105085451 I am getting this: [QUOTE] t/01basic.t ......................... ok # Failed test 'error parsing non-existent does_not_exist.xml' # at t/02parse.t line 238. # 'Could not create file parser context for file "does_not_exist.xml": No error at t/02parse.t line 237. # ' # doesn't match '(?-xism:\ACould not create file parser context for file "does_not_exist\.xml": No\ such\ file\ or...

Is there a "Starts With" or "Contains" I can use in my SQL query ??
Hi,   I have a piece of code written where I am trying to pull out certian fields based on them containing a certain letter eg C or S ???? Is there a simple piece of code I can use for this. At the moment I am using "AND sl.Name IN ('CDL') " & _.......but this will not return the rows that contain CDL ?  Any Ideas much APPRECIATED ?  You would use the LIKE keyword for that:http://msdn.microsoft.com/en-us/library/ms179859.aspxLike "AD sl.Name LIKE '%CDL%'"That will return anything where that name has CDL in it. Cheers, &nb...

The DataWindow "Retrieve" method is returning "Select Error: ORA-00942: table or view does not exist" error.
Hi I am getting "Select Error: ORA-00942: table or view does not exist" error when I try to retrieve data through Datawindow. The code I am using is "THIS.RETRIEVE(wo_no)". This code is returning "Select Error: ORA-00942: table or view does not exist" error. Please some one can help on this. Thanks, Ravi. I've usually seen this error when I don't have permission to select on a table. -- Evita Chapa Senior Systems Analyst Command Technologies, Inc. <Ravi> wrote in message news:425fa7c0.6322.1681692777@sybase.com... &...

The DataWindow "Retrieve" method is returning "Select Error: ORA-00942: table or view does not exist" error.
Hi, I am getting "Select Error: ORA-00942: table or view does not exist" error when I try to RETRIEVE from datawindow. my code is "this.retrieve(wo_no)". Please some one can help me on this. Thanks, Ravi. Please don't crosspost - already answered you in the datawindow forum. -- Evita Chapa Senior Systems Analyst Command Technologies, Inc. <Ravi> wrote in message news:425fa64e.6317.1681692777@sybase.com... > Hi, > > > I am getting "Select Error: ORA-00942: table or view does > not exist" error when I t...

Web resources about - Retrieve guid from DB error: "Guid should contain 32 digits with 4 dashes" - asp.net.getting-started

Resources last updated: 1/19/2016 3:52:03 PM