How to Find Mismatch Column Names from Two Different Datatable

Hello Everyone,

I have two tables:

Table 1 is Default Table in which we have required columns that are mandatory.
Table 2 is the Input Table which has the possibility to have more or less columns than Table 1

Question: I want to find the column names that are not there in the Input Table (Table 2).

Thankyou

Dim defaultColumns As List(Of String) = New List(Of String) From {“Column1”, “Column2”, “Column3”} ’ List of required columns in Table 1
Dim inputColumns As List(Of String) = New List(Of String) From {“Column1”, “Column3”, “Column4”} ’ List of columns in Table 2

//Use LINQ to find the columns that are present in defaultColumns but not in inputColumns
Dim missingColumns As IEnumerable(Of String) = defaultColumns.Where(Function(col) Not inputColumns.Contains(col))

//Convert the IEnumerable to a List(Of String) if needed
Dim missingColumnsList As List(Of String) = missingColumns.ToList()

//Output the missing columns
For Each column In missingColumnsList
Console.WriteLine("Missing column: " & column)
Next

Hi @Jaguti_Govindia

→ Use the Read Range workbook activity to read the excel1 file and store in a datatable called dtTable1.
→ Use another Read Range workbook activity to read the excel2 file and store in a datatable called dtTable2.
→ Then use the assign activity and create a List of String Datatype Variable called List_MissingColumns.

- Assign -> List_MissingColumns = New List(Of String)

- Assign -> List_MissingColumns = dtTable1.Columns.Cast(Of DataColumn)().Select(Function(col) col.ColumnName).Except(dtTable2.Columns.Cast(Of DataColumn)().Select(Function(col) col.ColumnName)).ToList()

All Missing columns in the Table2 will store in List_MissingColumns Variable.

Hope it helps!!

Hey @Jaguti_Govindia

Use below mentioned LinQ in Assign Activity:

str_MissingColumn = String.Join(",",dt_Default.Columns.Cast(Of DataColumn).Select(Function(x) x.ToString).Except(dt_Input.Columns.Cast(Of DataColumn).Select(Function(x) x.ToString)).ToArray)

Note: Above query will give output as String (With all the Missing Columns)

Screenshot for your reference:

Regards,
Ajay Mishra

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.