kkpatel
(Kamal)
April 12, 2021, 10:45am
1
Hi All
In select method i want to pass variable for the column name. The column name may contain spaces. How to do that.
Passing variable for coulmn name as it will interact with multiple excels and reuse the same code.
currQtrDT.Select(“[currQtrDT.Columns(0).ToString]=”+“'”+row(0).ToString+“'”) throwing error.
prasath_S
(prasath S)
April 12, 2021, 10:50am
2
Hi @kkpatel
Please try this syntax
dtTable.Select(“[”+dtTable.Columns(0).ToString+“] = '”+CurrentRow(“name”).ToString+“'”)
kkpatel
(Kamal)
April 12, 2021, 10:54am
3
Syntax error: Missing operand after ‘21’ operator.
Getting above error.
kkpatel
(Kamal)
April 12, 2021, 10:56am
4
Its because of the single quote present in the data i guess.
prasath_S
(prasath S)
April 12, 2021, 10:59am
5
you can replace the single quote and try.
Hi @kkpatel , @prasath_S
currQtrDT.AsEnumerable.Select(Function(f1) f1.Field(Of String)(“Month Year”) = CurrentRow(“name”).ToString)
allows you to use column names with spaces.
kkpatel
(Kamal)
April 12, 2021, 11:09am
7
I don’t want to hard code the column name. I want to pass variable. Also the above method I am not able to understand properly.
Hi @kkpatel
You can passed a variable this way
currQtrDT.AsEnumerable.Select(Function(f1) f1. Field(Of String)(str_varField ) == CurrentRow(“name”).ToString)
where str_varField is a variable type of String
See @ppr LINQ learning materials for better understanding of LINQ syntax.
There are examples within the VB.Net Syntax available as well
1 Like