Row comparison

  • Thread starter Thread starter tma
  • Start date Start date
T

tma

Is there a way to compare the values of portions of two rows? For example,
can I test if RowA, columns A,B,C are equal to RowB columns A,B,C and all
the while ignoring columns D,E, and F?
 
Allow me to rephrase the question. :)

Short of a column-by-column string comparison, is there a way to compare two
datarows on every field but a transaction id for equality?

I don't necessarily need a row duplicated if the only difference between
them is my transaction id.

Does that make sense?
 
If I understand your question correctly - you want to compare every field in
a row against every field in another row, except for one field in each which
is like a PK field or something? If that's the case, I don't know of any
method that will do that for you. However, you can subclass a dataRow and
implement the .equals method or = operator. In doing so, you can check them
column by column (I know you don't want to do this, but if you subclass it,
you'll only have to write it once) excluding the columnindex of the column
that you don't want to include.

Actually, there is one thing you can do. You can create an Expression
column of type string that just is a concatenation of each of the other
columns wihtout the transaction ID. In this example, I'm just concatenating
two fields with the expression but you can do all of them
http://www.knowdotnet.com/articles/expressions.html . If they are integers
or whatever you'd need to cast them (but the expression syntax makes that
easy). Then, each row would have an extra column (that wouldn't affect your
updates or anythign else) that's the concatenation of all of your fields
without the Transaction ID. You could just compare that value in two (or
more ) columns and if it's the same, all of the fields are the same,
otherwise they are different.

This should do it for you, but if you need any help implementing it, let me
know.

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
 
Back
Top