Need to find the row index using DataTable.Select Method

Hi,

I have an excel file. like below.

I know the value of ID field. Based on the ID field can I find the row index. So that I can update the status field in the same row.

I know that we can get the value from a different column like this: FinalListLookUpDataTable.Select().Where(function(x) (x(“ID”).ToString = “abc12345”)).First()(“Email Value”).ToString but I want to get the row id so that I can update the status column.

I think is better to iterate through datatable and generate a new one with updated status. Then replace excel file

I have about 10,000 rows and it takes a long time to iterate. So wanted to check if there is a faster way.

Let me understand better. Do you need to set status to all rows? Can you explain more about the process?

Usually lookups take some time, anyway remember to execute in Run mode (not Debug) to measure real processing time. There is a huge difference in these cases

Get first / last index

dtData.AsEnumerable.ToList.FindIndex(Function (x) x(YourColNameOrIndex).toString.Equals(YourValue))

dtData.AsEnumerable.ToList.FindLastIndex(Function (x) x(YourColNameOrIndex).toString.Equals(YourValue))

Get all Indexes:

(From i In Enumerable.Range(0,dtData.Rows.Count)
Let v = dtData.Rows(i)("StringCol").toString.Trim.ToUpper
Where v.Equals("FINDME")
Select i).DefaultIfEmpty(-1).toArray
2 Likes

This is what I needed. Thankyou.

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