I have a process in which it reads an input excel, before starting the process I want it to check that the column names are correct and instead throw an exception. How can I do it?
At least following statement is needed
left side: arrColNames - Datatype: String()
YourDataTableVar.Columns.Cast(Of DataColumn).Select(Function (x) x.ColumnName).toArray
Maybe you can share with us on which criteria the correctness of columnname is evaluated
The columns have to have an exact name for example “Company”, Contract Number "etc, if they are not the same, I have to throw an exception.
The solution you have given me does not work for me, on the left side, is it an array variable with all the column names? Thanks
we did implement successfully the retrieval of columnnames often and it did work.
Yes, the statement is returning a string array with the column names as mentioned above:
and the settings for the variable looks like following:
the check can be implemented as following:
- define a string Array with the columnnames which has to be checked - arrColNameDef
- retrieve the colname as a string array with the statement from above
use an if activity:
arrColNames.Intersect(arrColNameDef).Count = arrColNameDef.Count And arrColNames.Count = arrColNameDef.Count
then Branch: do your action when it is matching
else branch: do the alternate e.g. throwing an error
find starter help here (checking 2 datatables with each other, but in general it is similar):
Check_2DT_hasSameColNames_V2.xaml (14.0 KB)
It worked. Thank you very much.
Perfect. Just do your final testing and mark the solving post as solution afterwards. So others can benefit from this. Thanks