so could anyone please advise me who I should send this to in order to have
it sorted out?


"Dallara" <someone@microsoft.com> wrote in message
news:#hyo6T6xEHA.3376@TK2MSFTNGP12.phx.gbl...

Ok, Ryan. Thanks for your attention.

Do you get 0 rows in which one of the result sets? Because it shows 2 result
sets. One with the expected result and another one, where the extra brackets
were added with the "wrong" result. Just like bellow:


--------------------------------------------------------------------------------------------------------------------------------------
C:\Temp>AdoTableSelectTest


LESS BRACKETS FILTER RESULTS

( Description = 'Type B' and Number = 7 ) and ( Code = 'B' )
Row Count: 0
Code - Number - Description
---------------------------



EXTRA BRACKETS FILTER RESULTS

( ((Description = 'Type B')) and ((Number = 7)) ) and ( Code = 'B' )
Row Count: 2
Code - Number - Description
---------------------------
B - 2 - Type B
B - 3 - Type B


C:\Temp>
--------------------------------------------------------------------------------------------------------------------------------------


Note that the values in the Number column in the 2nd result set are 2 & 3
respectively. But the filter clause says "Number = 7"(???).
If both result sets are returning 0 rows, then I don't know what it is. It
might be that you have a different MDAC or .NET Framework version where this
problem has already been fixed.


Many thanks,
Dalmo







"W.G. Ryan eMVP" <WilliamRyan@NoSpam.gmail.com> wrote in message
news:eJcEwwfxEHA.1452@TK2MSFTNGP11.phx.gbl...
> Dallara:
>
> I'm not sure I follow you - I copied the code below and ran it - and I'm
> getting 0 rows selected. When I change the code block to this :
> DataRow Row1 = Table.NewRow();
>
> Row1["Code"] = "A";
>
> Row1["Description"] = "Type A";
>
> Row1["Number"] = 1;
>
> Table.Rows.Add(Row1);
>
> I get exactly what I'd expect.
>
>
> --
> W.G. Ryan MVP (Windows Embedded)
>
> TiBA Solutions
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
>
>
> "Dallara" <someone@microsoft.com> wrote in message
> news:#7rGTIexEHA.2016@TK2MSFTNGP15.phx.gbl...
>> Hi
>>
>> Just found a bug in the System.Data.DataTable.Select() method in ADO.NET.
>> To reproduce the bug, just create a C# Console application with the code
>> bellow on the start up class and execute it.
>>
>> What happens is that in some specific situations when you add some extra
>> brackets to the filter string, rows that don't match the filter criteria
> are
>> selected. If you remove the brackets the select works fine. And it's not
>> a
>> matter of precedence as all conditions are joined by AND.
>>
>> In the spike bellow, one of the filter conditions is "Number = 7". This
>> condition doesn't match any rows in the test table. Even thought, in the
>> select where extra brackets are added to the filter, 2 rows that match
>> the
>> other conditions are improperly selected. These rows have Numbers 2 and 3
>> respectively (not 7).
>>
>>
>> Thanks,
>> Dallara



// --------------------------------------
// -- SPIKE TO CATCH THE BUG --
// --------------------------------------

using System;
using System.Data;

namespace AdoTableSelectSpike
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
TestAdoTableSelect();
}

protected static void TestAdoTableSelect()
{
DataTable Table = GetTestTable();

string Condition0 = "Description = 'Type B'";
string Condition1 = "Number = 7";
string Condition2 = "Code = 'B'";

string LessBracketsFilter = String.Format("( {0} and {1} ) and ( {2} )",
Condition0, Condition1, Condition2);
DataRow[] LessBracketsRows = Table.Select(LessBracketsFilter);
WriteResults(LessBracketsRows, LessBracketsFilter, "LESS BRACKETS FILTER
RESULTS");

string ExtraBracketsFilter = String.Format("( (({0})) and (({1})) ) and
( {2} )", Condition0, Condition1, Condition2);
DataRow[] ExtraBracketsRows = Table.Select(ExtraBracketsFilter);
WriteResults(ExtraBracketsRows, ExtraBracketsFilter, "EXTRA BRACKETS
FILTER RESULTS");
}

protected static DataTable GetTestTable()
{
DataTable Table = new DataTable("TestTable");

Table.Columns.Add("Code", typeof(System.String));
Table.Columns.Add("Description", typeof(System.String));
Table.Columns.Add("Number", typeof(System.Int32));

DataRow Row1 = Table.NewRow();
Row1["Code"] = "A";
Row1["Description"] = "Type A";
Row1["Number"] = 1;
Table.Rows.Add(Row1);

DataRow Row2 = Table.NewRow();
Row2["Code"] = "B";
Row2["Description"] = "Type B";
Row2["Number"] = 2;
Table.Rows.Add(Row2);

DataRow Row3 = Table.NewRow();
Row3["Code"] = "B";
Row3["Description"] = "Type B";
Row3["Number"] = 3;
Table.Rows.Add(Row3);

return Table;
}

protected static void WriteResults(DataRow[] Rows, string FilterString,
string ResultsCaption)
{
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine(ResultsCaption);
Console.WriteLine("");
Console.WriteLine(FilterString);
Console.WriteLine("Row Count: " + Rows.Length.ToString());
Console.WriteLine("Code - Number - Description");
Console.WriteLine("---------------------------");

foreach (DataRow Row in Rows)
{
string Line = String.Format(
"{0} - {1} - {2}",
Row["Code"].ToString(),
Row["Number"].ToString(),
Row["Description"].ToString());
Console.WriteLine(Line);
}

Console.WriteLine("");
}
}
}

// --------------------------------------

Re: Sorry to be a pain but THIS IS A REAL BUG... by Jeff

Jeff
Mon Nov 15 20:37:20 CST 2004

Is this a real problem for you, are are you just curious? Can't you just
use the techniqure that is working for you?

Also, the term is Parenthesis, not Bracket. A bracket is [ or possibly {, a
paren is (

Are there any other records where Code = B and Description = Type B? What
if you change the 7 to be a different number, do you still return the same 2
rows?

Jeff
"Dallara" <someone@microsoft.com> wrote in message
news:urcC6e3yEHA.2200@TK2MSFTNGP09.phx.gbl...
> so could anyone please advise me who I should send this to in order to
have
> it sorted out?
>
>
> "Dallara" <someone@microsoft.com> wrote in message
> news:#hyo6T6xEHA.3376@TK2MSFTNGP12.phx.gbl...
>
> Ok, Ryan. Thanks for your attention.
>
> Do you get 0 rows in which one of the result sets? Because it shows 2
result
> sets. One with the expected result and another one, where the extra
brackets
> were added with the "wrong" result. Just like bellow:
>
>
> --------------------------------------------------------------------------
------------------------------------------------------------
> C:\Temp>AdoTableSelectTest
>
>
> LESS BRACKETS FILTER RESULTS
>
> ( Description = 'Type B' and Number = 7 ) and ( Code = 'B' )
> Row Count: 0
> Code - Number - Description
> ---------------------------
>
>
>
> EXTRA BRACKETS FILTER RESULTS
>
> ( ((Description = 'Type B')) and ((Number = 7)) ) and ( Code = 'B' )
> Row Count: 2
> Code - Number - Description
> ---------------------------
> B - 2 - Type B
> B - 3 - Type B
>
>
> C:\Temp>
> --------------------------------------------------------------------------
------------------------------------------------------------
>
>
> Note that the values in the Number column in the 2nd result set are 2 & 3
> respectively. But the filter clause says "Number = 7"(???).
> If both result sets are returning 0 rows, then I don't know what it is. It
> might be that you have a different MDAC or .NET Framework version where
this
> problem has already been fixed.
>
>
> Many thanks,
> Dalmo
>
>
>
>
>
>
>
> "W.G. Ryan eMVP" <WilliamRyan@NoSpam.gmail.com> wrote in message
> news:eJcEwwfxEHA.1452@TK2MSFTNGP11.phx.gbl...
> > Dallara:
> >
> > I'm not sure I follow you - I copied the code below and ran it - and I'm
> > getting 0 rows selected. When I change the code block to this :
> > DataRow Row1 = Table.NewRow();
> >
> > Row1["Code"] = "A";
> >
> > Row1["Description"] = "Type A";
> >
> > Row1["Number"] = 1;
> >
> > Table.Rows.Add(Row1);
> >
> > I get exactly what I'd expect.
> >
> >
> > --
> > W.G. Ryan MVP (Windows Embedded)
> >
> > TiBA Solutions
> > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> >
> >
> > "Dallara" <someone@microsoft.com> wrote in message
> > news:#7rGTIexEHA.2016@TK2MSFTNGP15.phx.gbl...
> >> Hi
> >>
> >> Just found a bug in the System.Data.DataTable.Select() method in
ADO.NET.
> >> To reproduce the bug, just create a C# Console application with the
code
> >> bellow on the start up class and execute it.
> >>
> >> What happens is that in some specific situations when you add some
extra
> >> brackets to the filter string, rows that don't match the filter
criteria
> > are
> >> selected. If you remove the brackets the select works fine. And it's
not
> >> a
> >> matter of precedence as all conditions are joined by AND.
> >>
> >> In the spike bellow, one of the filter conditions is "Number = 7". This
> >> condition doesn't match any rows in the test table. Even thought, in
the
> >> select where extra brackets are added to the filter, 2 rows that match
> >> the
> >> other conditions are improperly selected. These rows have Numbers 2 and
3
> >> respectively (not 7).
> >>
> >>
> >> Thanks,
> >> Dallara
>
>
>
> // --------------------------------------
> // -- SPIKE TO CATCH THE BUG --
> // --------------------------------------
>
> using System;
> using System.Data;
>
> namespace AdoTableSelectSpike
> {
> class Class1
> {
> [STAThread]
> static void Main(string[] args)
> {
> TestAdoTableSelect();
> }
>
> protected static void TestAdoTableSelect()
> {
> DataTable Table = GetTestTable();
>
> string Condition0 = "Description = 'Type B'";
> string Condition1 = "Number = 7";
> string Condition2 = "Code = 'B'";
>
> string LessBracketsFilter = String.Format("( {0} and {1} ) and (
{2} )",
> Condition0, Condition1, Condition2);
> DataRow[] LessBracketsRows = Table.Select(LessBracketsFilter);
> WriteResults(LessBracketsRows, LessBracketsFilter, "LESS BRACKETS
FILTER
> RESULTS");
>
> string ExtraBracketsFilter = String.Format("( (({0})) and (({1})) ) and
> ( {2} )", Condition0, Condition1, Condition2);
> DataRow[] ExtraBracketsRows = Table.Select(ExtraBracketsFilter);
> WriteResults(ExtraBracketsRows, ExtraBracketsFilter, "EXTRA BRACKETS
> FILTER RESULTS");
> }
>
> protected static DataTable GetTestTable()
> {
> DataTable Table = new DataTable("TestTable");
>
> Table.Columns.Add("Code", typeof(System.String));
> Table.Columns.Add("Description", typeof(System.String));
> Table.Columns.Add("Number", typeof(System.Int32));
>
> DataRow Row1 = Table.NewRow();
> Row1["Code"] = "A";
> Row1["Description"] = "Type A";
> Row1["Number"] = 1;
> Table.Rows.Add(Row1);
>
> DataRow Row2 = Table.NewRow();
> Row2["Code"] = "B";
> Row2["Description"] = "Type B";
> Row2["Number"] = 2;
> Table.Rows.Add(Row2);
>
> DataRow Row3 = Table.NewRow();
> Row3["Code"] = "B";
> Row3["Description"] = "Type B";
> Row3["Number"] = 3;
> Table.Rows.Add(Row3);
>
> return Table;
> }
>
> protected static void WriteResults(DataRow[] Rows, string FilterString,
> string ResultsCaption)
> {
> Console.WriteLine("");
> Console.WriteLine("");
> Console.WriteLine(ResultsCaption);
> Console.WriteLine("");
> Console.WriteLine(FilterString);
> Console.WriteLine("Row Count: " + Rows.Length.ToString());
> Console.WriteLine("Code - Number - Description");
> Console.WriteLine("---------------------------");
>
> foreach (DataRow Row in Rows)
> {
> string Line = String.Format(
> "{0} - {1} - {2}",
> Row["Code"].ToString(),
> Row["Number"].ToString(),
> Row["Description"].ToString());
> Console.WriteLine(Line);
> }
>
> Console.WriteLine("");
> }
> }
> }
>
> // --------------------------------------
>
>



Re: Sorry to be a pain but THIS IS A REAL BUG... by Dallara

Dallara
Tue Nov 16 00:00:43 CST 2004

YES. THIS IS A REAL PROBLEM FOR US.

We develop accounting software and I'm glad we found this bug, otherwise we
would just be using Table.Select thinking that it's all good. BUT IT IS
NOT!!!!

ALSO THANKS FOR TEACHING ME A BIT OF YOUR US ENGLISH.
In UK, Australia and other English speaking countries ( is a bracket, [ is a
square bracket and { is a curly bracket.

The bug is there even if you want to ignore or workaround it, but this
doesn't change the fact that there's a serious SILENT bug in ADO.NET




"Jeff Dillon" <jeff@removeemergencyreporting.com> wrote in message
news:%23sKloU4yEHA.2012@TK2MSFTNGP15.phx.gbl...
> Is this a real problem for you, are are you just curious? Can't you just
> use the techniqure that is working for you?
>
> Also, the term is Parenthesis, not Bracket. A bracket is [ or possibly {,
> a
> paren is (
>
> Are there any other records where Code = B and Description = Type B? What
> if you change the 7 to be a different number, do you still return the same
> 2
> rows?
>
> Jeff
> "Dallara" <someone@microsoft.com> wrote in message
> news:urcC6e3yEHA.2200@TK2MSFTNGP09.phx.gbl...
>> so could anyone please advise me who I should send this to in order to
> have
>> it sorted out?
>>
>>
>> "Dallara" <someone@microsoft.com> wrote in message
>> news:#hyo6T6xEHA.3376@TK2MSFTNGP12.phx.gbl...
>>
>> Ok, Ryan. Thanks for your attention.
>>
>> Do you get 0 rows in which one of the result sets? Because it shows 2
> result
>> sets. One with the expected result and another one, where the extra
> brackets
>> were added with the "wrong" result. Just like bellow:
>>
>>
>> --------------------------------------------------------------------------
> ------------------------------------------------------------
>> C:\Temp>AdoTableSelectTest
>>
>>
>> LESS BRACKETS FILTER RESULTS
>>
>> ( Description = 'Type B' and Number = 7 ) and ( Code = 'B' )
>> Row Count: 0
>> Code - Number - Description
>> ---------------------------
>>
>>
>>
>> EXTRA BRACKETS FILTER RESULTS
>>
>> ( ((Description = 'Type B')) and ((Number = 7)) ) and ( Code = 'B' )
>> Row Count: 2
>> Code - Number - Description
>> ---------------------------
>> B - 2 - Type B
>> B - 3 - Type B
>>
>>
>> C:\Temp>
>> --------------------------------------------------------------------------
> ------------------------------------------------------------
>>
>>
>> Note that the values in the Number column in the 2nd result set are 2 & 3
>> respectively. But the filter clause says "Number = 7"(???).
>> If both result sets are returning 0 rows, then I don't know what it is.
>> It
>> might be that you have a different MDAC or .NET Framework version where
> this
>> problem has already been fixed.
>>
>>
>> Many thanks,
>> Dalmo
>>
>>
>>
>>
>>
>>
>>
>> "W.G. Ryan eMVP" <WilliamRyan@NoSpam.gmail.com> wrote in message
>> news:eJcEwwfxEHA.1452@TK2MSFTNGP11.phx.gbl...
>> > Dallara:
>> >
>> > I'm not sure I follow you - I copied the code below and ran it - and
>> > I'm
>> > getting 0 rows selected. When I change the code block to this :
>> > DataRow Row1 = Table.NewRow();
>> >
>> > Row1["Code"] = "A";
>> >
>> > Row1["Description"] = "Type A";
>> >
>> > Row1["Number"] = 1;
>> >
>> > Table.Rows.Add(Row1);
>> >
>> > I get exactly what I'd expect.
>> >
>> >
>> > --
>> > W.G. Ryan MVP (Windows Embedded)
>> >
>> > TiBA Solutions
>> > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
>> >
>> >
>> > "Dallara" <someone@microsoft.com> wrote in message
>> > news:#7rGTIexEHA.2016@TK2MSFTNGP15.phx.gbl...
>> >> Hi
>> >>
>> >> Just found a bug in the System.Data.DataTable.Select() method in
> ADO.NET.
>> >> To reproduce the bug, just create a C# Console application with the
> code
>> >> bellow on the start up class and execute it.
>> >>
>> >> What happens is that in some specific situations when you add some
> extra
>> >> brackets to the filter string, rows that don't match the filter
> criteria
>> > are
>> >> selected. If you remove the brackets the select works fine. And it's
> not
>> >> a
>> >> matter of precedence as all conditions are joined by AND.
>> >>
>> >> In the spike bellow, one of the filter conditions is "Number = 7".
>> >> This
>> >> condition doesn't match any rows in the test table. Even thought, in
> the
>> >> select where extra brackets are added to the filter, 2 rows that match
>> >> the
>> >> other conditions are improperly selected. These rows have Numbers 2
>> >> and
> 3
>> >> respectively (not 7).
>> >>
>> >>
>> >> Thanks,
>> >> Dallara
>>
>>
>>
>> // --------------------------------------
>> // -- SPIKE TO CATCH THE BUG --
>> // --------------------------------------
>>
>> using System;
>> using System.Data;
>>
>> namespace AdoTableSelectSpike
>> {
>> class Class1
>> {
>> [STAThread]
>> static void Main(string[] args)
>> {
>> TestAdoTableSelect();
>> }
>>
>> protected static void TestAdoTableSelect()
>> {
>> DataTable Table = GetTestTable();
>>
>> string Condition0 = "Description = 'Type B'";
>> string Condition1 = "Number = 7";
>> string Condition2 = "Code = 'B'";
>>
>> string LessBracketsFilter = String.Format("( {0} and {1} ) and (
> {2} )",
>> Condition0, Condition1, Condition2);
>> DataRow[] LessBracketsRows = Table.Select(LessBracketsFilter);
>> WriteResults(LessBracketsRows, LessBracketsFilter, "LESS BRACKETS
> FILTER
>> RESULTS");
>>
>> string ExtraBracketsFilter = String.Format("( (({0})) and (({1})) )
>> and
>> ( {2} )", Condition0, Condition1, Condition2);
>> DataRow[] ExtraBracketsRows = Table.Select(ExtraBracketsFilter);
>> WriteResults(ExtraBracketsRows, ExtraBracketsFilter, "EXTRA BRACKETS
>> FILTER RESULTS");
>> }
>>
>> protected static DataTable GetTestTable()
>> {
>> DataTable Table = new DataTable("TestTable");
>>
>> Table.Columns.Add("Code", typeof(System.String));
>> Table.Columns.Add("Description", typeof(System.String));
>> Table.Columns.Add("Number", typeof(System.Int32));
>>
>> DataRow Row1 = Table.NewRow();
>> Row1["Code"] = "A";
>> Row1["Description"] = "Type A";
>> Row1["Number"] = 1;
>> Table.Rows.Add(Row1);
>>
>> DataRow Row2 = Table.NewRow();
>> Row2["Code"] = "B";
>> Row2["Description"] = "Type B";
>> Row2["Number"] = 2;
>> Table.Rows.Add(Row2);
>>
>> DataRow Row3 = Table.NewRow();
>> Row3["Code"] = "B";
>> Row3["Description"] = "Type B";
>> Row3["Number"] = 3;
>> Table.Rows.Add(Row3);
>>
>> return Table;
>> }
>>
>> protected static void WriteResults(DataRow[] Rows, string FilterString,
>> string ResultsCaption)
>> {
>> Console.WriteLine("");
>> Console.WriteLine("");
>> Console.WriteLine(ResultsCaption);
>> Console.WriteLine("");
>> Console.WriteLine(FilterString);
>> Console.WriteLine("Row Count: " + Rows.Length.ToString());
>> Console.WriteLine("Code - Number - Description");
>> Console.WriteLine("---------------------------");
>>
>> foreach (DataRow Row in Rows)
>> {
>> string Line = String.Format(
>> "{0} - {1} - {2}",
>> Row["Code"].ToString(),
>> Row["Number"].ToString(),
>> Row["Description"].ToString());
>> Console.WriteLine(Line);
>> }
>>
>> Console.WriteLine("");
>> }
>> }
>> }
>>
>> // --------------------------------------
>>
>>
>
>



Re: Sorry to be a pain but THIS IS A REAL BUG... by Jeff

Jeff
Tue Nov 16 14:43:19 CST 2004

If you want help, please answer all my questions, not just the first, or the
ones that are easy to answer.



"Dallara" <someone@microsoft.com> wrote in message
news:OK6S0H6yEHA.1192@tk2msftngp13.phx.gbl...
> YES. THIS IS A REAL PROBLEM FOR US.
>
> We develop accounting software and I'm glad we found this bug, otherwise
we
> would just be using Table.Select thinking that it's all good. BUT IT IS
> NOT!!!!
>
> ALSO THANKS FOR TEACHING ME A BIT OF YOUR US ENGLISH.
> In UK, Australia and other English speaking countries ( is a bracket, [ is
a
> square bracket and { is a curly bracket.
>
> The bug is there even if you want to ignore or workaround it, but this
> doesn't change the fact that there's a serious SILENT bug in ADO.NET
>
>
>
>
> "Jeff Dillon" <jeff@removeemergencyreporting.com> wrote in message
> news:%23sKloU4yEHA.2012@TK2MSFTNGP15.phx.gbl...
> > Is this a real problem for you, are are you just curious? Can't you
just
> > use the techniqure that is working for you?
> >
> > Also, the term is Parenthesis, not Bracket. A bracket is [ or possibly
{,
> > a
> > paren is (
> >
> > Are there any other records where Code = B and Description = Type B?
What
> > if you change the 7 to be a different number, do you still return the
same
> > 2
> > rows?
> >
> > Jeff
> > "Dallara" <someone@microsoft.com> wrote in message
> > news:urcC6e3yEHA.2200@TK2MSFTNGP09.phx.gbl...
> >> so could anyone please advise me who I should send this to in order to
> > have
> >> it sorted out?
> >>
> >>
> >> "Dallara" <someone@microsoft.com> wrote in message
> >> news:#hyo6T6xEHA.3376@TK2MSFTNGP12.phx.gbl...
> >>
> >> Ok, Ryan. Thanks for your attention.
> >>
> >> Do you get 0 rows in which one of the result sets? Because it shows 2
> > result
> >> sets. One with the expected result and another one, where the extra
> > brackets
> >> were added with the "wrong" result. Just like bellow:
> >>
> >>
> >> -----------------------------------------------------------------------
---
> > ------------------------------------------------------------
> >> C:\Temp>AdoTableSelectTest
> >>
> >>
> >> LESS BRACKETS FILTER RESULTS
> >>
> >> ( Description = 'Type B' and Number = 7 ) and ( Code = 'B' )
> >> Row Count: 0
> >> Code - Number - Description
> >> ---------------------------
> >>
> >>
> >>
> >> EXTRA BRACKETS FILTER RESULTS
> >>
> >> ( ((Description = 'Type B')) and ((Number = 7)) ) and ( Code = 'B' )
> >> Row Count: 2
> >> Code - Number - Description
> >> ---------------------------
> >> B - 2 - Type B
> >> B - 3 - Type B
> >>
> >>
> >> C:\Temp>
>
>> -------------------------------------------------------------------------
-
> > ------------------------------------------------------------
> >>
> >>
> >> Note that the values in the Number column in the 2nd result set are 2 &
3
> >> respectively. But the filter clause says "Number = 7"(???).
> >> If both result sets are returning 0 rows, then I don't know what it is.
> >> It
> >> might be that you have a different MDAC or .NET Framework version where
> > this
> >> problem has already been fixed.
> >>
> >>
> >> Many thanks,
> >> Dalmo
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> "W.G. Ryan eMVP" <WilliamRyan@NoSpam.gmail.com> wrote in message
> >> news:eJcEwwfxEHA.1452@TK2MSFTNGP11.phx.gbl...
> >> > Dallara:
> >> >
> >> > I'm not sure I follow you - I copied the code below and ran it - and
> >> > I'm
> >> > getting 0 rows selected. When I change the code block to this :
> >> > DataRow Row1 = Table.NewRow();
> >> >
> >> > Row1["Code"] = "A";
> >> >
> >> > Row1["Description"] = "Type A";
> >> >
> >> > Row1["Number"] = 1;
> >> >
> >> > Table.Rows.Add(Row1);
> >> >
> >> > I get exactly what I'd expect.
> >> >
> >> >
> >> > --
> >> > W.G. Ryan MVP (Windows Embedded)
> >> >
> >> > TiBA Solutions
> >> > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> >> >
> >> >
> >> > "Dallara" <someone@microsoft.com> wrote in message
> >> > news:#7rGTIexEHA.2016@TK2MSFTNGP15.phx.gbl...
> >> >> Hi
> >> >>
> >> >> Just found a bug in the System.Data.DataTable.Select() method in
> > ADO.NET.
> >> >> To reproduce the bug, just create a C# Console application with the
> > code
> >> >> bellow on the start up class and execute it.
> >> >>
> >> >> What happens is that in some specific situations when you add some
> > extra
> >> >> brackets to the filter string, rows that don't match the filter
> > criteria
> >> > are
> >> >> selected. If you remove the brackets the select works fine. And it's
> > not
> >> >> a
> >> >> matter of precedence as all conditions are joined by AND.
> >> >>
> >> >> In the spike bellow, one of the filter conditions is "Number = 7".
> >> >> This
> >> >> condition doesn't match any rows in the test table. Even thought, in
> > the
> >> >> select where extra brackets are added to the filter, 2 rows that
match
> >> >> the
> >> >> other conditions are improperly selected. These rows have Numbers 2
> >> >> and
> > 3
> >> >> respectively (not 7).
> >> >>
> >> >>
> >> >> Thanks,
> >> >> Dallara
> >>
> >>
> >>
> >> // --------------------------------------
> >> // -- SPIKE TO CATCH THE BUG --
> >> // --------------------------------------
> >>
> >> using System;
> >> using System.Data;
> >>
> >> namespace AdoTableSelectSpike
> >> {
> >> class Class1
> >> {
> >> [STAThread]
> >> static void Main(string[] args)
> >> {
> >> TestAdoTableSelect();
> >> }
> >>
> >> protected static void TestAdoTableSelect()
> >> {
> >> DataTable Table = GetTestTable();
> >>
> >> string Condition0 = "Description = 'Type B'";
> >> string Condition1 = "Number = 7";
> >> string Condition2 = "Code = 'B'";
> >>
> >> string LessBracketsFilter = String.Format("( {0} and {1} ) and (
> > {2} )",
> >> Condition0, Condition1, Condition2);
> >> DataRow[] LessBracketsRows = Table.Select(LessBracketsFilter);
> >> WriteResults(LessBracketsRows, LessBracketsFilter, "LESS BRACKETS
> > FILTER
> >> RESULTS");
> >>
> >> string ExtraBracketsFilter = String.Format("( (({0})) and (({1})) )
> >> and
> >> ( {2} )", Condition0, Condition1, Condition2);
> >> DataRow[] ExtraBracketsRows = Table.Select(ExtraBracketsFilter);
> >> WriteResults(ExtraBracketsRows, ExtraBracketsFilter, "EXTRA BRACKETS
> >> FILTER RESULTS");
> >> }
> >>
> >> protected static DataTable GetTestTable()
> >> {
> >> DataTable Table = new DataTable("TestTable");
> >>
> >> Table.Columns.Add("Code", typeof(System.String));
> >> Table.Columns.Add("Description", typeof(System.String));
> >> Table.Columns.Add("Number", typeof(System.Int32));
> >>
> >> DataRow Row1 = Table.NewRow();
> >> Row1["Code"] = "A";
> >> Row1["Description"] = "Type A";
> >> Row1["Number"] = 1;
> >> Table.Rows.Add(Row1);
> >>
> >> DataRow Row2 = Table.NewRow();
> >> Row2["Code"] = "B";
> >> Row2["Description"] = "Type B";
> >> Row2["Number"] = 2;
> >> Table.Rows.Add(Row2);
> >>
> >> DataRow Row3 = Table.NewRow();
> >> Row3["Code"] = "B";
> >> Row3["Description"] = "Type B";
> >> Row3["Number"] = 3;
> >> Table.Rows.Add(Row3);
> >>
> >> return Table;
> >> }
> >>
> >> protected static void WriteResults(DataRow[] Rows, string
FilterString,
> >> string ResultsCaption)
> >> {
> >> Console.WriteLine("");
> >> Console.WriteLine("");
> >> Console.WriteLine(ResultsCaption);
> >> Console.WriteLine("");
> >> Console.WriteLine(FilterString);
> >> Console.WriteLine("Row Count: " + Rows.Length.ToString());
> >> Console.WriteLine("Code - Number - Description");
> >> Console.WriteLine("---------------------------");
> >>
> >> foreach (DataRow Row in Rows)
> >> {
> >> string Line = String.Format(
> >> "{0} - {1} - {2}",
> >> Row["Code"].ToString(),
> >> Row["Number"].ToString(),
> >> Row["Description"].ToString());
> >> Console.WriteLine(Line);
> >> }
> >>
> >> Console.WriteLine("");
> >> }
> >> }
> >> }
> >>
> >> // --------------------------------------
> >>
> >>
> >
> >
>
>



Re: Sorry to be a pain but THIS IS A REAL BUG... by Dallara

Dallara
Tue Nov 16 22:50:56 CST 2004

> Are there any other records where Code = B and Description = Type B?
> What if you change the 7 to be a different number, do you still return the
> same 2 rows?
>
You can see in the spike I sent.
3 rows in total, 2 of them have Code=B and Description=Type B and 1 has
Code=A and Description=Type A.
The Number filter can be anything that doesn't match the actual values and
you can still see the bug.

All data is created in the code and then I run Select twice (without and
with extra parentheses).

Thanks



"Jeff Dillon" <jeff@removeemergencyreporting.com> wrote in message
news:O7DJdzBzEHA.2016@TK2MSFTNGP15.phx.gbl...
> If you want help, please answer all my questions, not just the first, or
> the
> ones that are easy to answer.
>
>
>
> "Dallara" <someone@microsoft.com> wrote in message
> news:OK6S0H6yEHA.1192@tk2msftngp13.phx.gbl...
>> YES. THIS IS A REAL PROBLEM FOR US.
>>
>> We develop accounting software and I'm glad we found this bug, otherwise
> we
>> would just be using Table.Select thinking that it's all good. BUT IT IS
>> NOT!!!!
>>
>> ALSO THANKS FOR TEACHING ME A BIT OF YOUR US ENGLISH.
>> In UK, Australia and other English speaking countries ( is a bracket, [
>> is
> a
>> square bracket and { is a curly bracket.
>>
>> The bug is there even if you want to ignore or workaround it, but this
>> doesn't change the fact that there's a serious SILENT bug in ADO.NET
>>
>>
>>
>>
>> "Jeff Dillon" <jeff@removeemergencyreporting.com> wrote in message
>> news:%23sKloU4yEHA.2012@TK2MSFTNGP15.phx.gbl...
>> > Is this a real problem for you, are are you just curious? Can't you
> just
>> > use the techniqure that is working for you?
>> >
>> > Also, the term is Parenthesis, not Bracket. A bracket is [ or possibly
> {,
>> > a
>> > paren is (
>> >
>> > Are there any other records where Code = B and Description = Type B?
> What
>> > if you change the 7 to be a different number, do you still return the
> same
>> > 2
>> > rows?
>> >
>> > Jeff
>> > "Dallara" <someone@microsoft.com> wrote in message
>> > news:urcC6e3yEHA.2200@TK2MSFTNGP09.phx.gbl...
>> >> so could anyone please advise me who I should send this to in order to
>> > have
>> >> it sorted out?
>> >>
>> >>
>> >> "Dallara" <someone@microsoft.com> wrote in message
>> >> news:#hyo6T6xEHA.3376@TK2MSFTNGP12.phx.gbl...
>> >>
>> >> Ok, Ryan. Thanks for your attention.
>> >>
>> >> Do you get 0 rows in which one of the result sets? Because it shows 2
>> > result
>> >> sets. One with the expected result and another one, where the extra
>> > brackets
>> >> were added with the "wrong" result. Just like bellow:
>> >>
>> >>
>> >> -----------------------------------------------------------------------
> ---
>> > ------------------------------------------------------------
>> >> C:\Temp>AdoTableSelectTest
>> >>
>> >>
>> >> LESS BRACKETS FILTER RESULTS
>> >>
>> >> ( Description = 'Type B' and Number = 7 ) and ( Code = 'B' )
>> >> Row Count: 0
>> >> Code - Number - Description
>> >> ---------------------------
>> >>
>> >>
>> >>
>> >> EXTRA BRACKETS FILTER RESULTS
>> >>
>> >> ( ((Description = 'Type B')) and ((Number = 7)) ) and ( Code = 'B' )
>> >> Row Count: 2
>> >> Code - Number - Description
>> >> ---------------------------
>> >> B - 2 - Type B
>> >> B - 3 - Type B
>> >>
>> >>
>> >> C:\Temp>
>>
>>> -------------------------------------------------------------------------
> -
>> > ------------------------------------------------------------
>> >>
>> >>
>> >> Note that the values in the Number column in the 2nd result set are 2
>> >> &
> 3
>> >> respectively. But the filter clause says "Number = 7"(???).
>> >> If both result sets are returning 0 rows, then I don't know what it
>> >> is.
>> >> It
>> >> might be that you have a different MDAC or .NET Framework version
>> >> where
>> > this
>> >> problem has already been fixed.
>> >>
>> >>
>> >> Many thanks,
>> >> Dalmo
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> "W.G. Ryan eMVP" <WilliamRyan@NoSpam.gmail.com> wrote in message
>> >> news:eJcEwwfxEHA.1452@TK2MSFTNGP11.phx.gbl...
>> >> > Dallara:
>> >> >
>> >> > I'm not sure I follow you - I copied the code below and ran it - and
>> >> > I'm
>> >> > getting 0 rows selected. When I change the code block to this :
>> >> > DataRow Row1 = Table.NewRow();
>> >> >
>> >> > Row1["Code"] = "A";
>> >> >
>> >> > Row1["Description"] = "Type A";
>> >> >
>> >> > Row1["Number"] = 1;
>> >> >
>> >> > Table.Rows.Add(Row1);
>> >> >
>> >> > I get exactly what I'd expect.
>> >> >
>> >> >
>> >> > --
>> >> > W.G. Ryan MVP (Windows Embedded)
>> >> >
>> >> > TiBA Solutions
>> >> > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
>> >> >
>> >> >
>> >> > "Dallara" <someone@microsoft.com> wrote in message
>> >> > news:#7rGTIexEHA.2016@TK2MSFTNGP15.phx.gbl...
>> >> >> Hi
>> >> >>
>> >> >> Just found a bug in the System.Data.DataTable.Select() method in
>> > ADO.NET.
>> >> >> To reproduce the bug, just create a C# Console application with the
>> > code
>> >> >> bellow on the start up class and execute it.
>> >> >>
>> >> >> What happens is that in some specific situations when you add some
>> > extra
>> >> >> brackets to the filter string, rows that don't match the filter
>> > criteria
>> >> > are
>> >> >> selected. If you remove the brackets the select works fine. And
>> >> >> it's
>> > not
>> >> >> a
>> >> >> matter of precedence as all conditions are joined by AND.
>> >> >>
>> >> >> In the spike bellow, one of the filter conditions is "Number = 7".
>> >> >> This
>> >> >> condition doesn't match any rows in the test table. Even thought,
>> >> >> in
>> > the
>> >> >> select where extra brackets are added to the filter, 2 rows that
> match
>> >> >> the
>> >> >> other conditions are improperly selected. These rows have Numbers 2
>> >> >> and
>> > 3
>> >> >> respectively (not 7).
>> >> >>
>> >> >>
>> >> >> Thanks,
>> >> >> Dallara
>> >>
>> >>
>> >>
>> >> // --------------------------------------
>> >> // -- SPIKE TO CATCH THE BUG --
>> >> // --------------------------------------
>> >>
>> >> using System;
>> >> using System.Data;
>> >>
>> >> namespace AdoTableSelectSpike
>> >> {
>> >> class Class1
>> >> {
>> >> [STAThread]
>> >> static void Main(string[] args)
>> >> {
>> >> TestAdoTableSelect();
>> >> }
>> >>
>> >> protected static void TestAdoTableSelect()
>> >> {
>> >> DataTable Table = GetTestTable();
>> >>
>> >> string Condition0 = "Description = 'Type B'";
>> >> string Condition1 = "Number = 7";
>> >> string Condition2 = "Code = 'B'";
>> >>
>> >> string LessBracketsFilter = String.Format("( {0} and {1} ) and (
>> > {2} )",
>> >> Condition0, Condition1, Condition2);
>> >> DataRow[] LessBracketsRows = Table.Select(LessBracketsFilter);
>> >> WriteResults(LessBracketsRows, LessBracketsFilter, "LESS BRACKETS
>> > FILTER
>> >> RESULTS");
>> >>
>> >> string ExtraBracketsFilter = String.Format("( (({0})) and (({1})) )
>> >> and
>> >> ( {2} )", Condition0, Condition1, Condition2);
>> >> DataRow[] ExtraBracketsRows = Table.Select(ExtraBracketsFilter);
>> >> WriteResults(ExtraBracketsRows, ExtraBracketsFilter, "EXTRA
>> >> BRACKETS
>> >> FILTER RESULTS");
>> >> }
>> >>
>> >> protected static DataTable GetTestTable()
>> >> {
>> >> DataTable Table = new DataTable("TestTable");
>> >>
>> >> Table.Columns.Add("Code", typeof(System.String));
>> >> Table.Columns.Add("Description", typeof(System.String));
>> >> Table.Columns.Add("Number", typeof(System.Int32));
>> >>
>> >> DataRow Row1 = Table.NewRow();
>> >> Row1["Code"] = "A";
>> >> Row1["Description"] = "Type A";
>> >> Row1["Number"] = 1;
>> >> Table.Rows.Add(Row1);
>> >>
>> >> DataRow Row2 = Table.NewRow();
>> >> Row2["Code"] = "B";
>> >> Row2["Description"] = "Type B";
>> >> Row2["Number"] = 2;
>> >> Table.Rows.Add(Row2);
>> >>
>> >> DataRow Row3 = Table.NewRow();
>> >> Row3["Code"] = "B";
>> >> Row3["Description"] = "Type B";
>> >> Row3["Number"] = 3;
>> >> Table.Rows.Add(Row3);
>> >>
>> >> return Table;
>> >> }
>> >>
>> >> protected static void WriteResults(DataRow[] Rows, string
> FilterString,
>> >> string ResultsCaption)
>> >> {
>> >> Console.WriteLine("");
>> >> Console.WriteLine("");
>> >> Console.WriteLine(ResultsCaption);
>> >> Console.WriteLine("");
>> >> Console.WriteLine(FilterString);
>> >> Console.WriteLine("Row Count: " + Rows.Length.ToString());
>> >> Console.WriteLine("Code - Number - Description");
>> >> Console.WriteLine("---------------------------");
>> >>
>> >> foreach (DataRow Row in Rows)
>> >> {
>> >> string Line = String.Format(
>> >> "{0} - {1} - {2}",
>> >> Row["Code"].ToString(),
>> >> Row["Number"].ToString(),
>> >> Row["Description"].ToString());
>> >> Console.WriteLine(Line);
>> >> }
>> >>
>> >> Console.WriteLine("");
>> >> }
>> >> }
>> >> }
>> >>
>> >> // --------------------------------------
>> >>
>> >>
>> >
>> >
>>
>>
>
>