Solved

How to know if a string is GUID?

Posted on 2013-02-03
6
340 Views
Last Modified: 2013-02-03
I have a sql statement that joins to 2 tables and brings back an ID row. I changed the design and the new IDs are integers. The old IDs are GUIDs.

How can I know if the ID is GUID and not an integer? based on that, i want to use an if-else statement.

thanks
0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Aeriden
ID: 38849312
You can create a SQL Function that would return whether a GUID is valid:

http://ask.sqlservercentral.com/questions/23114/best-way-to-check-that-a-stringvarchar-guid-is-val.html
0
 
LVL 7

Author Comment

by:Camillia
ID: 38849324
want to do it in C#, ASP.net. But let me look at your link
0
 
LVL 9

Assisted Solution

by:Aeriden
Aeriden earned 250 total points
ID: 38849416
Oh, that is even easier.  Check out http://www.geekzilla.co.uk/View8AD536EF-BC0D-427F-9F15-3A1BC663848E.htm (using a Regular Expression for a GUID test).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38849450
Why not use Guid.Tryparse?
0
 
LVL 7

Author Comment

by:Camillia
ID: 38849475
so if (Guid.Tryparse(field) = true)

?
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 38849542
No.

Guid converted;

if (Guid.TryParse("{81a130d2-502f-4cf1-a376-63edeb000e9f}", out converted) == true)
{
    // converted will hold the converted value if the TryParse succeeds
}

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

710 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