Column1 column2 column3
a b c
b b a
c b d
a d c
b c d
c b a
Get the above data of the column2 “d” appears and skip the below data
Hi @Ranga_prasad ,
Could you provide the Expected output for the Input data provided?
Also explain a bit more as to what do you want to perform on that data.
sarathi125
(Parthasarathi)
February 28, 2022, 9:08am
3
Hi @Ranga_prasad ,
First try to get the row index where the column2 has “d” in it.
yourDataTable.AsEnumerable().[Select](Function(row) row.Field(Of String)("Column2")).ToList().FindIndex(Function(col) col = "d")
Using this index you can use Linq’s Skip and Take function to get the rows before this index
yourDataTable.AsEnumerable().Skip(0).Take(intIndexIdentified).CopyToDataTable()
1 Like
Yoichi
(Yoichi)
February 28, 2022, 9:14am
4
Hi,
Can you try the following expression?
dt = dt.AsEnumerable.Take(dt.AsEnumerable.Select(Function(r,i) if(r("Column2").ToString="d",i,-1)).Max()+1).CopyToDataTable()
Regards,
Column1 column2 column3
a b c
b b a
c b d
in this way i need output.
ppr
(Peter Preuss)
February 28, 2022, 9:41am
6
dtData.asEnumerable.TakeWhile(Function (x) Not x(1).toString.Trim.ToUpper.Equals("D")).CopyToDataTable
in case of we would also expect empty results then use toList like:
Result | List(Of DataRow) =
dtData.asEnumerable.TakeWhile(Function (x) Not x(1).toString.Trim.ToUpper.Equals(“D”)).toList
and evaluate on the Result.Count if CopyToDataTable can be executed or not
Hi Sarathi ,
Your linq query is working fine,
but i have to skip all the data after “d” in column2.
can you help me out of this.
o/p: Column1 column2 column3
a b c
b b a
c b d
Thanks & regards,
Ranga.
sarathi125
(Parthasarathi)
February 28, 2022, 11:32am
9
@Ranga_prasad ,
You have to get the index using my first Linq Query into a variable named “intIndexIdentified” and use the second linq query to get the rows before the row which has “d” in column2.
system
(system)
Closed
March 3, 2022, 3:23pm
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.