Solved

How to know if a string is GUID?

Posted on 2013-02-03
6
328 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calling stored proc in EDMX 11 24
Double hop Issues between IIS Server and Exchange Server/ Exchange Web Service 4 46
Syntax Error 2 47
SQL Login 17 40
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now