How to identify if a column exists in a datatable

Hi. I use this assign activity to extract a invoice-field but it´s not a mandatory field and when the field are´t filled in by the user the column doesn´t exists in the extrated data set. How should I detect if the column exists or not?

ds.Tables(“invoicemark”).Rows(0)(“Value”).ToString

Hi @Zlotzky

use the below condition to validate whether the column is existing or not

(From dc In dt.Columns.Cast(Of DataColumn) Select dc.ColumnName).ToArray().Contains(columnname)

Hope it helps you

Regards,
Nived N
Happy Automation

2 Likes

As an alternate:
YourDataTableVar.Columns.Cast(Of DataColumn).Any(Function (x) x.ColumnName.Equals(YourColNameStringVar))
and will return true if column exists

1 Like

@Zlotzky,

you can also do it way as below,
Read your excel
use for each, item type should be system.data.datacolumn

image

add if condition for specific column i wish to get

Cheers,
Pankaj