By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,527 Members | 945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,527 IT Pros & Developers. It's quick & easy.

DataView.Sort NaN

P: n/a
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
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)


Mar 17 '06 #1
Share this Question
Share on Google+
3 Replies

P: n/a
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.

Mar 18 '06 #2

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

Mar 18 '06 #3

P: n/a
"INeedADip" <in*******> wrote in news:1142646485.717703.265910
isn't foo null....aren't you adding a (new Object[]{0}) which goes into
so that makes foo null and not a double.

No, foo is a computed column:
new DataColumn("foo",Type.GetType("System.Double"),"ba r / 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.

Mar 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.