PC Review


Reply
Thread Tools Rate Thread

DataView.Sort NaN

 
 
gilly3
Guest
Posts: n/a
 
      17th Mar 2006
I have a column in a DataView that contains NaN. When I attempt to Sort on
this column, I get:

MESSAGE: Index was outside the bounds of the array.
SOURCE: System.Data
STACKTRACE:
at System.Data.Index.Sort(Int32 left, Int32 right)
at System.Data.Index.InitRecords()
at System.Data.Index..ctor(DataTable table, Int32[] indexDesc,
DataViewRowState recordStates, IFilter rowFilter)
at System.Data.DataTable.GetIndex(Int32[] indexDesc, DataViewRowState
recordStates, IFilter rowFilter)
at System.Data.DataTable.GetIndex(String sort, DataViewRowState
recordStates, IFilter rowFilter)
at System.Data.DataView.UpdateIndex(Boolean force)
at System.Data.DataView.SetIndex(String newSort, DataViewRowState
newRowStates, DataFilter newRowFilter)
at System.Data.DataView.set_Sort(String value)

Here is my repro code:

public static void sortDataView()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("bar",Type.GetType("System.Double")));
dt.Columns.Add(new DataColumn("foo",Type.GetType("System.Double"),
"bar / 0"));
dt.Rows.Add(new Object[]{0});
dt.Rows.Add(new Object[]{0});
dt.DefaultView.Sort = "foo ASC"; // <-- This Line Errors!
}

However, if I debug with VS.NET 2003 and break just before the sort command
and run it in the Command Window, then continue, there is no error. I just
copied the line from the source that errors into the Command Window and it
executes just fine. I continue and my app runs without errors.

How do I fix this? (Besides fixing my divide by zero error)

thanks

-ivan.
 
Reply With Quote
 
 
 
 
DonGiaconia
Guest
Posts: n/a
 
      18th Mar 2006
Well I don't know if this helps too much, or if i'm just saying
something obvious, but NaN represents Not a Number, so it looks like it
is trying to sort with an invalid value in there.

 
Reply With Quote
 
INeedADip
Guest
Posts: n/a
 
      18th Mar 2006
isn't foo null....aren't you adding a (new Object[]{0}) which goes into
bar.
so that makes foo null and not a double.

 
Reply With Quote
 
gilly3
Guest
Posts: n/a
 
      20th Mar 2006
"INeedADip" <(E-Mail Removed)> wrote in news:1142646485.717703.265910
@j33g2000cwa.googlegroups.com:

> isn't foo null....aren't you adding a (new Object[]{0}) which goes into
> bar.
> so that makes foo null and not a double.
>


No, foo is a computed column:

>new DataColumn("foo",Type.GetType("System.Double"),"bar / 0");


So foo contains bar / 0, which is, of course, always NaN.

The interesting thing is I can Sort a DataView with just one NaN value in
the sort column without error. If there are two or more NaN values in the
sort column, I get the error when I sort.

-ivan.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataview Sort Charles A. Lackman Microsoft ADO .NET 6 5th Feb 2007 09:02 AM
Dataview sort Cindy Lee Microsoft C# .NET 2 12th Jan 2007 08:21 PM
Dataview will not sort Raymond Lewallen Microsoft VB .NET 9 8th Nov 2004 08:18 PM
Re: DataView Sort William Ryan eMVP Microsoft ADO .NET 0 29th Jul 2004 11:04 PM
DataView sort fails to sort on fields with comma in field names Mone Hsieh Microsoft ADO .NET 1 14th May 2004 09:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:24 PM.