Solved

How to know if a string is GUID?

Posted on 2013-02-03
6
331 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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