Search
Closed
as By Design Help for as By Design

1
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 504999
Opened: 10/28/2009 5:31:23 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
DataTable に定義した DataColumn の型と、DataTable.Select の条件式から推論して処理される型が異なる場合、DataTable.Select の結果がおかしくなります。
再現コードでは、DataTable の項目の型は "String" としていますが、Select の条件式では値に引用符がないために "数値" として処理されます。このような場合、エラーが発生したり、エラーが発生しなくても結果が期待通りでなかったりします。

この件は、次のサイトで原因が解説されていました。
Min (5) must be less than or equal to max (-1) in a Range object
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/aa45873f-5374-47c0-b5ed-a31c2e1fab32/#14cf0ef6-1759-4192-aca2-0a15b75d5589

異なる型でのソート結果を使用すること自体、不適切な処理だと思います。型が異なる場合、バイナリーサーチではなく線形探索で処理するようになっていれば、検索スピードは遅くなったとしても予測不能な結果になることは避けられると思います。

なお本件は、Bata1 の Visual Studio 2010、.NET Frame 4.0 の環境でも発生することを確認しました。
Details (expand)
製品言語
日本語
製品名
Visual Studio 2008 SP1
オペレーティング システム
Windows Vista
オペレーティング システム言語
日本語
再現手順
// ケース1
{
DataTable dt = new DataTable();
dt.Columns.Add("col", typeof(string));
foreach (string value in new[] { "1", "2", "10", "20" })
{
dt.Rows.Add(value);
}

// エラー ArgumentException
// Range オブジェクトの Min (1) は、max (-1) 以下でなければなりません。
// 英語:Min (1) must be less than or equal to max (-1) in a Range object
dt.Select("col = 10");
}
// ケース2
{
DataTable dt = new DataTable();
dt.Columns.Add("col", typeof(string));
foreach (string value in new[] { "1", "2", "10" })
{
dt.Rows.Add(value);
}

// アサートに失敗
Debug.Assert(dt.Select("col = 2").Length == 1);
}
実際の結果
Select の結果が正しくない。
期待した結果
Select が正しく機能する。
TAP コード (お持ちの場合のみ)
 
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 11/1/2009 at 9:09 PM
この度は、フィードバックをお送りいただき、誠にありがとうございます。 現在、お送りいただきました報告内容に基づき問題を調査中ですので、しばらくお待ちください。 よろしくお願いいたします。

[Problem Description]
When the type of DataColumn defined to DataTable differs from the type that's handled by inferring from a DataTable.Select query, the result of DataTable.Select is incorrect.

In the source code in Repro Steps, the type of DataTable is specified as "String." However, because a value is not quotation-marked in a Select query, it's handled as "numerical value". In this a case, an error occurs, or (even if no error occurs,) an unexpected result is returned.

The cause of the issue is explained in the following forum thread: "Min (5) must be less than or equal to max (-1) in a Range object" (http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/aa45873f-5374-47c0-b5ed-a31c2e1fab32/#14cf0ef6-1759-4192-aca2-0a15b75d5589)

I think using a sorted result with a different type itself is an inappropriate processing. If two different types are handled by linear search rather than binary search, the search speed might be slower, but at least an unpredictable result could be avoided.

For your information, I confirmed the issue occurred in Visual Studio 2010 Beta 1 and .NET Framework 4.0 Beta 1.

[Repro Steps]
// Case 1
{
DataTable dt = new DataTable();
dt.Columns.Add("col", typeof(string));
foreach (string value in new[] { "1", "2", "10", "20" })
{
dt.Rows.Add(value);
}

// Error ArgumentException
// Range オブジェクトの Min (1) は、max (-1) 以下でなければなりません。
// English: Min (1) must be less than or equal to max (-1) in a Range object
dt.Select("col = 10");
}
// Case 2
{
DataTable dt = new DataTable();
dt.Columns.Add("col", typeof(string));
foreach (string value in new[] { "1", "2", "10" })
{
dt.Rows.Add(value);
}

// Assert failed.
Debug.Assert(dt.Select("col = 2").Length == 1);
}

[Actual Results]
The result of Select is incorrect.

[Expected Results]
"Select" should work correctly.
Posted by Microsoft on 11/2/2009 at 12:52 AM
Thanks for your feedback. We are routing this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 11/2/2009 at 1:14 AM
(こちらは、[投稿者: Microsoft、投稿日時: 2009/11/02 0:52] の和訳です。)

フィードバックをお寄せいただき、ありがとうございます。 こちらのバグに関しましては、該当する機能を専門で担当している製品チームに報告させていただきます。 今後は、同チームが問題を再調査し、次期リリース版での修正について判断する予定です。 よろしくお願いいたします。

Visual Studio 製品チーム
Posted by Microsoft on 11/9/2009 at 3:14 PM
In case 1, put single quotation marks around 10 or use LINQ to DataSet.

In case 2, put single quotation marks around 2 or use LINQ to DataSet.

Overall, when doing a select to a string column, please include numbers within single quotation marks so that they are interpreted as strings rather than numbers.
Posted by Microsoft on 11/10/2009 at 12:30 AM
(こちらは、[投稿者: Microsoft、投稿日時: 2009/11/09 15:14] の和訳です。)

Case 1 においては、単一引用符 (') で 10 を囲むか、LINQ to DataSet を使用してください。 Case 2 においては、単一引用符 (') で 2 を囲むか、LINQ to DataSet を使用してください。

まとめますと、文字列カラムに対して select を行なう場合は、数字が数値ではなく文字列として解釈されるように、単一引用符 (') で囲ってください。