Linq query to extract the particular value depends upon value passed in variable

Hi all,

I have an variable with value assigned and depends upon the variable value I need to extract the data of that particular value from Excel.

For example below is the data in Excel

Column 1 Column 2
1 Abc
2 Xyz
3 pqr


So,the output should be Xyz.

I want to do it in linq query?

Help me on this

Hi @yashashwini2322,

Please, try the following in a assign activity:

(From row In dt.AsEnumerable()
                                Where row.Field(Of Integer)("Column1") = Var_str
                                Select row.Field(Of String)("Column2")).FirstOrDefault()

Hi @yashashwini2322

→ Use the read range workbook activity to read the excel and store in a datatable called dt
You can use the below expression in assign activity,

- Assign -> Var_str = "2"
- Assign -> Result = dt.AsEnumerable().Where(Function(row) row("Column1").ToString() = Var_str).Select(Function(row) row("Column2").ToString()).DefaultIfEmpty("Value not found").FirstOrDefault()

Check the below image for better understanding,

Hope it helps!!

Hi @yashashwini2322

Try below expression

.Where(Function(row) row(“Column1”).ToString() = Var_str)
.Select(Function(row) row(“Column2”).ToString())
.DefaultIfEmpty(“Value not found”)

Hope it will helps you :slight_smile:


Please find the query below

yourdatatablevariable.asenumerable.where(function(x) x(0).tostring.equals(yourstringvariable).trim).select(function(y) y(1).tostring).firstordefault

Sreejith S S

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