Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I return a cursor to a DataSet from Oracle. I would like to order the rows in the DataTable so I could rank them. However the order would be be the result of "column3" / "column4". I have tried the following with no luck.

DataTable crsDT = ds.Tables[0].Copy();
DataRow[] rows = new DataRow[crsDT.Rows.Count-1];
rows = crsDT.Select("column4 != 0","column3 / column4");


I know I can loop through the data and get my intended result, but I wanted to try something new to see if it would be more efficient.

Is this possible or should I go a different direction?
Posted
Updated 12-Nov-10 4:55am
v2

Could you not do something like this?

foreach( DataRow row in ds.Tables[0].Select("","column3 / column4") )
{
 int Rank = row.Item("column3") / row.Item("column4");

 // Do something with row and rank?
}
 
Share this answer
 
Comments
badprog 12-Nov-10 11:23am    
MarqW,
System.IndexOutOfRangeException was unhandled by user code
Message="Cannot find column Column3 / Column4."
Source="System.Data"

Blew up in the ForEach definition.
Would my syntax be wrong? I know that the column names are correct, because I get the column names via
ds.Tables[0].Columns[3].ColumnName
ds.Tables[0].Columns[4].ColumnName
MarqW 12-Nov-10 11:24am    
Hmm, try changing it to this:

ds.Tables[0].Select("","[column3] / [column4]") )

and maybe need brackets

ds.Tables[0].Select("","([column3] / [column4])") )

I'll be honest, I've not actually tried these :-)
How about adding a computed column to the DataTable and using that?
 
Share this answer
 
Comments
badprog 12-Nov-10 11:31am    
Thanks Henry,
I am trying this now
Type tType = typeof(double);
DataColumn myCol = new DataColumn("RANK", tType, "Column3 / Column4");
crsDT.Columns.Add(myCol);
I just have to figure out what to do when Column4 is zero. Once I do, I think that will work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900