BUG: Sort on GUID Columns Works Differently on DataSet and SqlServer (326603)



The information in this article applies to:

  • Microsoft Visual C# .NET (2002)

This article was previously published under Q326603

SYMPTOMS

When you use the SqlTypes.SqlGuid.CompareTo() method to compare different SqlGuids, you may receive incorrect comparison results. This inconsistent behavior does not occur when you use the CompareTo() method of the System.Guid class.

CAUSE

The System.Guid class and SqlTypes.SqlGuid class implement the CompareTo() method differently. SqlGuid implements the CompareTo() method according to the behavior in SQL server (only the last 6 bytes are considered), however, Guid considers all 16 bytes.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET, and create a new Microsoft Visual C# .NET project. By default, Form1 is created.
  2. Add a new button to Form1.
  3. In Solution Explorer, right-click Form1.cs, and then click View Code.
  4. Add the following namespace on top of the file:
    using System.Data.SqlTypes;
    						
  5. Add the following code to the button1_Click event:
    			Guid g1 = new Guid("3AAAAAAABBBBCCCCDDDD2EEEEEEEEEEE");
    			Guid g2 = new Guid("1AAAAAAABBBBCCCCDDDD3EEEEEEEEEEE");
    			SqlGuid sg1 = new SqlGuid(g1);
    			SqlGuid sg2 = new SqlGuid(g2);
    
    			int GuidCompareResult = g1.CompareTo(g2);
    			int SqlGuidCompareResult = sg1.CompareTo(sg2);
    
    			Console.WriteLine ("CompareTo returned {0} for Guid and {1} for SqlGuid",
    				GuidCompareResult, SqlGuidCompareResult);
    						
  6. Press F5 to run the application. Click the button that you added.
  7. Check the Output window. You see the following:
    CompareTo returned 1 for Guid and -1 for SqlGuid
    						

Modification Type:MajorLast Reviewed:12/13/2002
Keywords:kbbug KB326603