PoshCode Archive  Artifact [14b5b76844]

Artifact 14b5b768445c5a7fcc705b80c792fe646aa27e394d53210b82354360f90a93ea:

  • File Compare-Table-amp-DataRow.ps1 — part of check-in [101dba4b89] at 2018-06-10 13:09:28 on branch trunk — Compare 2 system.Data.DataSet each containing 1 table (user: Bernd Kriszio size: 1449)

# encoding: ascii
# api: powershell
# title: Compare Table & DataRow
# description: Compare 2 system.Data.DataSet each containing 1 table
# version: 0.1
# type: function
# author: Bernd Kriszio
# license: CC0
# function: Compare-DataRow
# x-poshcode-id: 2389
# x-archived: 2016-10-19T03:58:45
# x-published: 2011-11-25T04:18:00
#
#
function Compare-DataRow
{
    param( $a, $b)
    
    # @bernd_k http://pauerschell.blogspot.com/
    
    $diff = ''
    $a_columncount = $a.Table.columns.count
    $b_columncount = $b.Table.columns.count
   
    if ( $a_columncount -ne $b_columncount)
    {
        Write-host "Tables have different number of columns"
    }
    foreach ( $i in 0..($a_columncount - 1))
    {
        if ($a.item($i) -ne $b.item($i))
        {
            $diff += ' ' +  $a.item($i) + '  <> ' +  $b.item($i) +';'
        }
    }     
    $diff
}

function Compare-Table
{
    param( $a, $b)
    
    # @bernd_k http://pauerschell.blogspot.com/

    $diff = ''
    $a_rowcount = $a.Rows.count
    $b_rowcount = $b.Rows.count
   
    if ( $a_rowcount -ne $b_rowcount)
    {
        Write-host "Tables have different number of columns"
    }
    foreach ( $i in 0..($a_rowcount - 1))
    {
         Compare-DataRow $a.rows[$i] $b.rows[$i]
    }     
    $diff
}

Compare-DataRow $a.tables[0].rows[0] $b.tables[0].rows[0] 
Compare-Table   ($a.tables[0]) ($b.tables[0])