Sort bug in DataTable.Select with Windows 2003 SP 1

G

Guest

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.

This behaviour is only seen on machines running Win2k3 with Win2k3 SP1
installed.

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]);
}
}
}
}
 
G

Guest

John,

I tried with the indexer and the results are the same. So it's not a bug
displayed only by using foreach. If this were the case, the bug would likely
be in the Array class's Enumerator, which would manifest itself in both
cases, and most likely many other areas of .Net as well. In this case, the
bug only occurs when the filter sent to DataTable.Select is not trivial, so
it seems that the bug is clearly somewhere in the changes made to System.Data
in the Win2k3 SP1 update.

I was expecting my post to be addressed by MS by now. I made the post from
an account linked to an MSDN Universal subscription and MS say they respond
within 24 hours. We really need this bug to be looked at, as sort order is a
pretty fundamental piece of functionality.

Niall
 

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