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?
@Marisa_Ontiveros1
At least following statement is needed
assign activity
left side: arrColNames - Datatype: String()
right side:
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:
Condition:
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.
@Marisa_Ontiveros1
Perfect. Just do your final testing and mark the solving post as solution afterwards. So others can benefit from this. Thanks
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.