tags:

views:

84

answers:

2

i have two data tables with the same structure

the first one has one row of the second one

the second one has set of rows

what i want is to get the row which comes next to the row of the first data table in the second data table.

the first data table his name is :: temp

the second data table his name is :: dt

i do the following:

DataTable temp = new DataTable();
temp = dt.Clone();
DataColumn[] keyColumn = new DataColumn[1];
keyColumn[0] = temp.Columns["photoId"];
temp.PrimaryKey = keyColumn;
temp = (DataTable)(Session["currentImage"]);
DataRow[] drr = new DataRow[1];

index = dt.Rows.IndexOf(temp.Rows[0]);

but the index always comes with one value = -1

although the temp.rows[0] its contents changed all the time

when i write dt.Rows.IndexOf(dt.Rows[1]) for examble i get 1

but this is not what i want to do ,, what i want to do exactly is to get the datarow next to the datarow of the first dataTable in the second dataTable

please help me.

+5  A: 

A DataRow knows which table it's in, so two rows with the same data but in different tables are still different rows.

Why don't you look for a row with the same primary ID, or whatever else is meaningful in your case?

Jon Skeet
+3  A: 

IndexOf() using the default comparer of the object to perform a match. The default comparer of most object is reference comparison, which is explaining why you're keep getting -1.

For the same reason:

int iA = 0;
int iB = 0;
object oA = 0;
object oB = 0;

iA == iB = true;
oA == oB = false
Nissim
could u explain the idea more, please
http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx
Nissim
thank u so much