Find row index in Dataset

E

El Camino

Hey boyz and girlz

Im trying to find the index of a row that im selecting in
dtsInfo

heres the code of the dtsInfo select

Dim strExpr As String

Dim strSort As String

strExpr = "Name=CIE"

strSort = "Name DESC"

Dim foundRows As DataRow() = dtsInfo.Tables(0).Select
(strExpr, strSort, DataViewRowState.CurrentRows)

need to find the row index that dtsInfo will return

Thanx!
 
B

Bernie Yaeger

Hi,

Use this function and call it as specified to get any row's index:

Public Function findindex(ByVal dt As DataTable, ByVal dr As DataRow) As
Integer
' signature:

' dim funcs as new imcfunctionlib.functions

' dim xint as integer

' xint = funcs.findindex(dsmanifest.tables(0),irow)

' when you call findindex inside a loop the current irow index is returned
with

' idex = findindex(ods.Tables(0), irow)

' at the same time, this

' MessageBox.Show(irow("imcacct"))

' equals

' MessageBox.Show(ods.Tables(0).Rows(idex)("imcacct"))

' once outside the loop - see dataworks for more info

Dim i As Integer

For i = 0 To dt.Rows.Count - 1

If Object.ReferenceEquals(dt.Rows(i), dr) Then

Return i

End If

Next

Return -1

End Function

HTH,

Bernie Yaeger
 
C

Cor

Hi El Camino,
Dim foundRows As DataRow() = dtsInfo.Tables(0).Select
(strExpr, strSort, DataViewRowState.CurrentRows)

Returns an array of selected rows from the dataset not the index.

As far as I know till now for that the fastest is
\\\
for index as integer = 0 to dtsInfo.tables(0).rowscound-1
if true your expresiopn
'found the index
exit for
end if
next
///

I hope this helps a little bit?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top