the IndexOf() method returns -1 all the time
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
p开发者_JAVA百科lease help me.
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?
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
精彩评论