comparing one row to the former row

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

OK, can't get the answer I need, so I'll ask another way:

How can I compare one row to another in sequence? That is,
For Each irow In dsanreport.Tables(0).Rows

I want to compare the second row to the first to see if certain cols have
changed. For example, if the first row is the same 'club' and the second,
has the price of entry (pentry) changed from the first row to the second?

Thanks for any help.

Bernie Yaeger
 
Bernie:

Funny you mention it, I just finished a project doing this today..I'll send
you the code in the morning. It'll be in C# but the attachement will be
..txt (even though it's C#) b/c of firewall restrictions.
 
DataTable dt = dsanreport.Tables[0]
for( intx=0 x<dt.Rows.Count;x++)
{
DataRow dr = dt.Rows[x];
if (x>0)
{
if( dt.Rows[x-1]["colname"])
etc...
}
}
 
Hi Andrew,

Of course - I should be using a simple for loop, not a for each loop.
Thanks!

Bernie

Andrew de la Harpe said:
DataTable dt = dsanreport.Tables[0]
for( intx=0 x<dt.Rows.Count;x++)
{
DataRow dr = dt.Rows[x];
if (x>0)
{
if( dt.Rows[x-1]["colname"])
etc...
}
}
Bernie Yaeger said:
OK, can't get the answer I need, so I'll ask another way:

How can I compare one row to another in sequence? That is,
For Each irow In dsanreport.Tables(0).Rows

I want to compare the second row to the first to see if certain cols have
changed. For example, if the first row is the same 'club' and the second,
has the price of entry (pentry) changed from the first row to the second?

Thanks for any help.

Bernie Yaeger
 
Bernie:

I see Andrew posted essentially the same code that I'll send you tomorrow.
I have a few overloads so you can pass an array of columns in with an
IComparable interface, but the logic is pretty much the same as what he did.
I actually did it with a foreach, but the Integer based compare is slightly
quicker, particularly for large tables...
 
Hi Bernie,

This question you ask is the oldest way of doing dataprocessing

You sort a file (you use the dataview) and goes throug it from start to end
everytime saving the keys as previous keys and do something when there is a
change.

The first thing you do is to fill the previous keys with the first keys
before you start the loop.

I hope I did not misunderstood you?

Cor
 
Hi Cor,

Yes, that's what I have to do. Andrew's code made me realize that the
simple 'for' loop is the way to get this done, not a 'for each' loop.

Thanks,

Bernie
 
Bernie:

Here's the simple piece I mentioned,

Try

If Not optDuplicates.Checked Or AllData.Tbl_Job_Tracking Is Nothing Then
Exit Sub

Dim dr As DataRow

Dim CompareVal As String = String.Empty

Dim BaseValue As String = String.Empty

Duplicates = New ArrayList

For Each dr In AllData.Tbl_Job_Tracking.Select("", FieldName)

If IsDBNull(dr(FieldName)) Then

BaseValue = String.Empty

Else

BaseValue = CType(dr(FieldName), String)

End If

If BaseValue = CompareVal Then

Duplicates.Add(CompareVal)

Debug.WriteLine(CompareVal)

End If

CompareVal = BaseValue

Next

Catch ex As InvalidCastException

Debug.Assert(False, ex.ToString)

End Try



I'm sending you the IComparable chunk in a few minutes.



Cheers,



Bill
 
Back
Top