Microsoft KB Archive/326603

= BUG: Sort on GUID Columns Works Differently on DataSet and SqlServer =

Article ID: 326603

Article Last Modified on 12/13/2002

-

APPLIES TO


 * Microsoft Visual C# .NET 2002 Standard Edition

-



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.



Steps to Reproduce the Behavior
 Start Microsoft Visual Studio .NET, and create a new Microsoft Visual C# .NET project. By default, Form1 is created. Add a new button to Form1. In Solution Explorer, right-click Form1.cs, and then click View Code.  Add the following namespace on top of the file: using System.Data.SqlTypes;   Add the following code to the button1_Click event: Guid g1 = new Guid(&quot;3AAAAAAABBBBCCCCDDDD2EEEEEEEEEEE&quot;); Guid g2 = new Guid(&quot;1AAAAAAABBBBCCCCDDDD3EEEEEEEEEEE&quot;); SqlGuid sg1 = new SqlGuid(g1); SqlGuid sg2 = new SqlGuid(g2);

int GuidCompareResult = g1.CompareTo(g2); int SqlGuidCompareResult = sg1.CompareTo(sg2);

Console.WriteLine (&quot;CompareTo returned {0} for Guid and {1} for SqlGuid&quot;,               GuidCompareResult, SqlGuidCompareResult);  Press F5 to run the application. Click the button that you added.</li>  Check the Output window. You see the following:

<pre class="fixed_text">CompareTo returned 1 for Guid and -1 for SqlGuid </li></ol>

Additional query words: Guid SqlGuid CompareTo

Keywords: kbbug KB326603

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.