views:

1451

answers:

3

I have two arrays of System.Data.DataRow objects which I want to compare. The rows have two columns A and B. Column A is a key and I want to find out which rows have had their B column changed and which rows have been added or deleted. How do I do this in PowerShell?

A: 

Do you need two arrays of DataRows? the DataRow object has a RowState property which will give you what you require. See the MSDN Docs: http://msdn.microsoft.com/en-us/library/system.data.datarow.rowstate.aspx

HollyStyles
A: 

@HollyStyles:

The reason i'm having two arrays of DataRow is that i'm pulling the data from two DBF files. So I guess what I want to do is compare two DBF files from PowerShell.

Manga Lee
+2  A: 

I wrote a script to do this a little while back. The script (Compare-QueryResults.ps1) is available here and you will also need my Run-SQLQuery script (available here) or you can replace that with a script or function of your own.

Basically, what the script does is take the results of each of your queries and break the datarows apart so that each field is its own object. It then uses Compare-Object to check for any differences between the data in those rows. It returns a comparison object that shows you all the differences between the data returned.

The results are an object, so you can save them to a variable and use Sort-Object or the Format-* cmdlets with them.

Good luck. If you have any problems with the scripts, let me know, I'd be happy to walk you through them. I've been using them for application testing, seeing what rows are being modified by different actions in a program.

Steven Murawski