none
Is there a way to get the row number after using .Select(strFilter)? RRS feed

  • Question

  • I am trying to build a class to make it easier to convert my ADO projects to ADO.Net.
    Is there a way to find the row number after using .Select(strFilter)?

    For Example, the following will tell me if the information I am looking for is in the Dataset.  What I need to find is the row number so that I can use it later.

       Private mobjDS As DataSet
       Private mobjRow As DataRow

       Public Function FindFirst(ByVal strFilter As String) As Boolean
          Dim dataRow() As DataRow = mobjDS.Tables("MyTable").Select(strFilter)
          If dataRow IsNot Nothing Then
             If dataRow.Length > 0 Then
                RowIndex = ?
                Return True
             Else
                Return False
             End If
          Else
             Return False
          End If
       End Function
      
    I would then be able to use RowIndex to get the starting position to begin returning info.

       mobjRow = mobjDS.Tables("MyTable").Rows(RowIndex )
       return mobjRow.Item(FieldName)

    Wednesday, February 24, 2010 6:21 PM

Answers

  • Hi Morgan,

    Asuming that your array of DataRow (dataRow()) containst just one row after Select and you want to get the index of that Row you can do:

    RowIndex = mobjDS.Tables("MyTable").Rows.IndexOf(dataRow(0))

    IndexOf receives one DataRow object which in this case will be your row substracted when you called Select.

    Please let me know if this helps.

    Thanks
    Juan


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, February 25, 2010 7:19 PM
    Moderator

All replies

  • This is how I did it in ADO; how can I do this in ADO.NET?

       Public Function ADOFindFirst(ByRef MySet As ADODB.Recordset, _
                                    ByVal Filter As String) As Boolean

          Dim mhRS As New ADODB.Recordset
          Dim mhMatch As Boolean = False

          Try
             mhRS = MySet.Clone
             mhRS.Filter = Filter

             If mhRS.RecordCount > 0 Then
                '// Match found - set to 1st found record
                mhRS.MoveFirst()
                MySet.Bookmark = mhRS.Bookmark
                mhMatch = True

             Else
                '// No match Found - Move to End
                If MySet.RecordCount > 0 Then
                   MySet.MoveLast()
                   MySet.MoveNext()
                End If
                mhMatch = False
             End If

          Catch ex As Exception
             '// Error
             mhMatch = False

          Finally
             mhRS.Close()
             mhRS = Nothing
          End Try

          Return mhMatch

       End Function
    Thursday, February 25, 2010 1:43 PM
  • Hi Morgan,

    Asuming that your array of DataRow (dataRow()) containst just one row after Select and you want to get the index of that Row you can do:

    RowIndex = mobjDS.Tables("MyTable").Rows.IndexOf(dataRow(0))

    IndexOf receives one DataRow object which in this case will be your row substracted when you called Select.

    Please let me know if this helps.

    Thanks
    Juan


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, February 25, 2010 7:19 PM
    Moderator
  • Thanks, this does exactly what I needed it to do.
    Thursday, February 25, 2010 9:35 PM