473,394 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DataView.Sort NaN

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.
Mar 17 '06 #1
3 4478
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
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.

Mar 18 '06 #3
"INeedADip" <in*******@gmail.com> 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"),"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.

-ivan.
Mar 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the...
9
by: Raymond Lewallen | last post by:
I have a dataview in which the sort property will not sort the dataview. Here's is a simple scenario similar to what I am doing: Class Foo Private Function Retrieve() As DataView ' Returns a...
7
by: Jason | last post by:
Is it possible to somehow sort a dataview, all on one column, but on different variables? That is, I have a 'Title' column in my dataview and I'd like to display first all "Directors" (sorted),...
1
by: troyblakely | last post by:
I am having trouble sorting a datagrid. I have read numerous posts on this and other lists, and tried most of the suggestions, but none of them have worked for me yet. I populate a dataset from two...
5
by: David Wender | last post by:
I want to create a dataview with a sort on multiple columns. However, when I use FindRows, I only want to search some of the columns, not all. Is this possible? I have not been able to make it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.