Compare header Names of 2 datatable

Hi team,

Can anyone tell me how i can compare headernames of 2 datatable.
Both of them contains 54 headers.
If there is a mismatch in headernames then BOT will throw Business exception

Hi Zara,

Try this

dt1.Columns(0).ToString=dt2.Columns(0).ToString

Hope it will work

tried…but its picking only first header name…i want to match all 54 with the another 54

then You have to use nested loop for this. Let me show

1 Like

if u have any reusable code for this…pls share

@Zara
with following statement you will get the column names as list:
YourDataTableVar.Columns.Cast(Of DataColumn).Select(Function (x) x.ColumnName).toList

with the data set operations you can identify if its matching or not e.g. with intersect or except

1 Like

Hi Zara,

Quick solution.

Cheers Sequence.xaml (10.4 KB)

1 Like

@Zara
find starter help here, using the set operation approach
Check_2DT_hasSameColNames.xaml (11.8 KB)

1 Like

CompareHeadersOfTwoExcels.zip (13.4 KB)
Hi,
Please find the attached workflow file.
Hope It can help. Mark as solution if it works

2 Likes

Hello,

help me understand if the column headers don’t match then how to print the header of the data table from which we were comparing? in respect to the below screenshot I am looking for the column’s name of DT1 in the Else part.

@indrajit.shah

lets find out the common rows:
dt1dt3Commons = dt1Cols.Intersect(dt3Cols).ToArray

lets find out the non common rows:
dt1Todt3Differences = dt1Cols.Except(dt1dt3Commons).ToArray
dt3Todt1Differences = dt3Cols.Except(dt1dt3Commons).ToArray

lets print it
grafik
“DT1 differs with: " + String.Join(”, " ,dt1Todt3Differences)
“DT3 differs with: " + String.Join(”, " ,dt3Todt1Differences)

find updated starter help here:
Check_2DT_hasSameColNames_V2.xaml (14.0 KB)

Kindly note:
the check was organized in order to rely not on same datacolumn positions. Just findout the different columns based on its names.

For a check on name, position and same column count, we can do very fast with following:
grafik

1 Like