Hi,
I'm trying to find in a dataset if the next value is the same and if it is take its value in another var.
ex.
abc 100 200
abc 150 100
abc 100 250
abx 100 230
abv 100 200
abv 150 100
the data set is ordered...
and i want to have
RESULT
abc 350 550
abx 100 230
abv 250 300
I was trying in this way... but... :(
for (int i = 0; i < dsLog.Tables[0].Rows.Count; i++)
{
cb = System.Convert.ToInt32(dsLog.Tables[1].Rows[i][0].ToString());
cs = System.Convert.ToInt32(dsLog.Tables[2].Rows[i][0].ToString());
fat = dsLog.Tables[0].Rows[i][0].ToString();
if (fat == dsLog.Tables[0].Rows[i+1][0].ToString())
{
cb += System.Convert.ToInt32(dsLog.Tables[1].Rows[i+1][0].ToString());
cs += System.Convert.ToInt32(dsLog.Tables[2].Rows[i+1][0].ToString());
fat = dsLog.Tables[0].Rows[i+1][0].ToString();
}
funcPutToListView(fat, cs.ToString(), cb.ToString());
}
Can you help me?
Daniel

1 answers
Try this:
answered one year ago by:
17279
82
thanks vulpes, infact i used something like this... but... don't know... i don't like its way of finding... is cause i'm using a dataset? i refer to the check of the first and the last element of the array.
17279
Whether you're using a dataset or anything else, I don't think it's possible to devise an algorithm for this kind of collation which doesn't treat the first and last elements specially, though sometimes its done outside the loop rather than within it.