Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare datarows

Status
Not open for further replies.

ludmann

Programmer
Apr 14, 2004
49
GB
Can someone tell me how to compare two datarows, without having to go through each field in the row? I want to see if they are different, and if yes do some other stuff.
I also need to use Trim() and ToLower()

Marika
 
fi you select the rows from database you can do like this:
select a, b, c, .... count(*) from table group by a, b, c ...

If the count(*) will be greater than 1 then you have there many than one identical row. Where is 1 rows are uniqie.

If you want to compare two columns
select .... from table where col1 <> col2, so you will select only fields where col1 differs from col2 To choose equals put = instead of <>.

from two tables is like this:
select .... from table1 left join table1 on table1.col= table2.col where table1.col is null. To choose euqals remove left and remove where table1.col ....

Ion Filipski
1c.bmp
 
Sorry, I forgot to mention I was talking about the DataRow of a DataTable from a DataSet

Marika
 
I think you can compare the results of .GetHashCode() for each of them.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Code:
if (myDataRow.GetHashCode() != myOtherDataRow.GetHashCode())
{
   // Rows are different
}

//
// Also..
//
if (myDataTable.Rows[0].GetHashCode() != myDataTable.Rows[1].GetHashCode())
{
   // Rows are different
}

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
don't play in this case with hashcodes. Let the database to do it and to give you the result. So, when you're creating the query to access records in database tables create such sql chich will give you all results without cheching that in your C# code.

Ion Filipski
1c.bmp
 
But if you've already made the query, you can use that to check in code. Probably not worth making another query to the database for this (slow).

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Chiph, if you make the application and the query string I think is better to make a small change in the query string than adding some additional C# code which will do all something instead of things what should be done by the database.
you want to see if there are row duplicates
for example you use
the query
"select a, b, c, d, e from xxx"
code
while(recordset.fetch....)
{
compare current row with all previous....
you should keep a copy of each record and do
one more loop there to compare....
}

but with sql logic:
"select a, b, c, d, e, count(*) as f from xxx group by a, b, c, d, e"
C# code:
while(recordset.fetch....)
{
if field f > 1 then there are duplicates,
more info, there are f duplicates...
}


Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top