i may get sheet with 100 or 1000 columns names i have to check if that certain one column available or not
how can i do that
@Tharusha_Fernando
give a try on:
YourDataTableVar.Columns.Cast(Of Datacolumn).Any(Function (x) x.ColumnName.Equals(“YourColumnNameToCheck”))
it will retrun true when it is present or false
can i add a list of coloum names to check instead of one
Yes, but also depends on your requirements:
Lets assume:
Variables
ColNames = YourDataTableVar.Columns.Cast(Of Datacolumn).Select(Function (x) x.ColumnName).toArray (DataType: String()
CheckNames = {“NameA”, “NameB”} (Datatype: String()
Option 1: True/False Result
Check Statement:
CheckNames.All(Function (x) ColNames.Contains(x))
it returns True if ColumnNames from CheckNames are present
Option 2: Not Present ColumnNames Array Result:
CheckNames.Except(ColNames).toArray
returns a string array with all names from CheckNames which were not found in ColNames
for example coloums are not in order as our list then what the move we should take
@Tharusha_Fernando
I didnt get you. can you elaborate more on your question (best with some sample data)
The order / positions from column names and check names is irrelevant for this code statements and will not affect the result
we have few columns so we have to check Age and fName is available or not
so if we take a list it going to check cell A1 and B1 right
for that what should we do
those fName column might be at the end or beginning
@Tharusha_Fernando
lets assume:
ColNames = {“home”,“city”…“age”,…“fname”, “town”}
CheckNames = {“age”, “fname”}
as mentitoned it will not influence and the returns will be correct
Try it.
it worked
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.