Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi!!!
I have a data-table whose content are as
FnYear     || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12
 
2001-2002  || 8 || 8 || 8 || 8 || 8 || 8 || 9 || 9 || 9 || 9  || 9  || 9
2002-2003  || 8 || 8 || 8 || 8 || 8 || 8 || 8 || 8 || 8 || 8.60  || 8.60 || 8.60


How to find when the value is changing in the datarow ?
Posted
Comments
Richard MacCutchan 3-Aug-12 9:22am    
Your question is far from clear. Where is this data, in a database, a file, memory? How are you trying to access it ...
Please think about what problem you are trying to solve before you write your question.
ujjwal uniyal 3-Aug-12 9:27am    
I have mentioned that data is in a datatable.
Philip Stuyck 3-Aug-12 9:38am    
you mean you want to find out when 1 changes into 2, 2 into 3, ... for the first ow, and when 8 changes into 9 on the second row right ?
You must have some code, please show what you got already.
ujjwal uniyal 3-Aug-12 9:41am    
No. sorry for the ambiguous question. I need to find when 8 changes to 9 or 8 changes to 8.60. for example in fnYear 2001-2002 it changes at column name 7 and in 2002-2003 it changes at column name 10
ujjwal uniyal 3-Aug-12 9:44am    
I have taken all the values for a particular financial year into a list (of String) but after that i am stuck .what to do ??

1 solution

Uh, am I missing something? This seems trivial.

int GetChangeIndex(DataRow row){
 double value = double.Parse(row.Cells[0].Value);
 
 for(int i = 1; i < row.Cells.Length; i++){
  double thiscell = double.Parse(row.Cells[i].Value);
  if(value != thiscell) return i;
  else value = thiscell;
 }

 return -1; // no change; you could also return
            // row.Cells.Length, or throw an exception
}
 
Share this answer
 

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