DataTable.Select Sort order bug

G

Guest

This is a repost of an earlier message. I have updated my discussions profile
to use my MSDN nospam alias that is linked with our MSDN subscription.

We originally discovered the bug in Windows 2003 after Win2k3 SP1 was
applied to the machines. However, since the original post, we have also
ascertained that the bug is reproducible on Windows XP after applying hotfix
891742 (http://support.microsoft.com/Default.aspx?kbid=891742).

By analysing the differences in System.Data between Framework 1.1SP1 and the
hotfixed version, it appears that the bug is due to a miscalculated index
used to index an array in System.Data.Select.CreateIndex().

This bug is critical for us, as many of our clients run our application
through terminal services on Windows 2003, and SP1 for Windows 2003 is no
longer in beta.

Below is the original post.
---------------

Win2k3 SP1 was recently applied to some of our unit testing machines and we
noticed some tests were failing, apparently due to sort order.

We believe there is a bug in DataTable.Select(string Filter, string Sort)
when the filter contains two subfilters joined with "AND". Our code attempts
to sort on the second column in the table, which works when the filter is
simple. However, when the filter is changed to join two conditions with
"AND", the results are sorted on the first column, even though we specify the
second column.

Here is the code to reproduce the bug.

using System;
using System.Data;

namespace DataTableSelectOrderBug
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string BuggyFilter = "Column3 = 8 and Column1 <> 20";
string WorkingFilter = "Column3 = 8";

Console.WriteLine("Correct results:");
RunOrderedSelect(WorkingFilter);

Console.WriteLine();
Console.WriteLine("Incorrect results:");
RunOrderedSelect(BuggyFilter);

Console.ReadLine();
}

static void RunOrderedSelect(string Filter)
{
DataTable TestTable = new DataTable("TestTable");
DataColumn Column1 = TestTable.Columns.Add("Column1", typeof(int));
DataColumn Column2 = TestTable.Columns.Add("Column2", typeof(int));
DataColumn Column3 = TestTable.Columns.Add("Column3", typeof(int));

TestTable.Rows.Add(new object[] { 3, 1, 8 });
TestTable.Rows.Add(new object[] { 2, 2, 8 });
TestTable.Rows.Add(new object[] { 1, 3, 8 });
TestTable.Rows.Add(new object[] { 4, 5, 8 });
TestTable.Rows.Add(new object[] { 5, 4, 8 });
TestTable.Rows.Add(new object[] { 6, 6, 8 });
TestTable.Rows.Add(new object[] { 7, 7, 8 });


DataRow[] SortedRows = TestTable.Select(Filter, Column2.ColumnName);
Console.WriteLine("Sorting on column: " + Column2.ColumnName + ", Filter:
" + Filter);
foreach (DataRow SortedRow in SortedRows)
{
Console.WriteLine(SortedRow[Column1] + " | " + SortedRow[Column2] + " |
" + SortedRow[Column3]);
}
}
}
}
 
K

Kevin Yu [MSFT]

Hi,

Thanks for posting. According to your description, it seems that this is a
known issue in .NET framework sp1. To get a hotfix for this issue, you can
try to contact Microsoft PSS directly. If this is a bug in our product,
getting the hotfix is free of charge. You can find contact information from
the following link:

http://support.microsoft.com/default.aspx?scid=fh;[ln];cntactms

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Kevin,

I'm sorry, but I don't think you are thinking of the same issue.

The issue we are experiencing is definitely NOT present in .Net Framework
1.1 SP1. We have been running .Net Framework 1.1 SP1 since mid last year and
did not experience this problem. When our Windows 2003 machines picked up
Windows 2003 SP1 (not Framework 1.1 SP1, which was already installed), this
bug was detected.

The issue is introduced specifically by Windows 2003 SP1 and hotfix 891742
(http://support.microsoft.com/Default.aspx?kbid=891742). If you run the code
I posted on a machine not running the Windows 2003 SP1 or this hotfix, you
will see the correct results. If you run it with that hotfix or Windows 2003
SP1, you will see that the sort order is incorrect.

The versions and contents of System.Data.dll change when you apply Windows
2003 SP1 or the aforementioned hotfix. The bug is introduced with this change.

Once again, I must mention that this issue is urgent for us.

Niall
 
K

Kevin Yu [MSFT]

Hi Niall,

Sorry for my misunderstanding. Thanks for your repro code, I tried it on my
machine, and it helped me successfully to reproduced the issue.

In my view, it has to be a bug in the sp1 and the hotfix. The best way to
resolve this issue is to call Microsoft PSS, after confirming it, they will
help you to work out another hotfix on this. If it is a bug on the product,
they will deliver the hotfix free of charge.

You can find your local PSS contact information from the following link

http://support.microsoft.com/common/international.aspx?rdpath=gp;en-us;offer
prophone

If anything is unclear, please feel free to reply to this post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Niall,

Since this issue is urgent, contacting PSS will be the best thing to do.
Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top