Hi, I am trying to get the rowindex of a datable with the following method:
assigns: i = From p In dt.Rows.IndexOf(Where p.Item(0).ToString.Equals(“…”))
Why I need the index ? To overwrite the row with write range.
Hi, I am trying to get the rowindex of a datable with the following method:
assigns: i = From p In dt.Rows.IndexOf(Where p.Item(0).ToString.Equals(“…”))
Why I need the index ? To overwrite the row with write range.
@B.D
give atry on following:
Assign
left side: arrIdx (integer array)
right side:
(From i in Enumerable.Range(0, yourDataTableVar.Rows.Count)
Where yourDataTableVar.Rows(i)(0).toString.Trim.Equals(“…”)
Select i).toArray
you will retrieve all matching index or an empty array if there were no matches found
Hi ppr, thanks.
Can you elaborate your code ? I don’t understand this part:
why are you trimming it ?
also why do I need to set a range. And why Enumerable ?
@B.D
derived from your inputs a statement was formulated to retrieve an int array with indexes of the rows within a datatable matching a particular value for a particular column
The main idea of statement is:
we do a trim when we check with equals to be more defensive when data comes e.g. from excel and risks that undetected blanks are trailing, leading (feel free to remove it)
Other way like below
Enumerable.Range(0,YourDataTable.Rows.Count).
Where(Function(i) YourDataTable.Rows(i)(0).ToString().Equals(“…”)).
ToArray
Thank you park. Always good to have alternative solutions.
Thanks for the explanation
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.