none
Obtaining a relative record or range of records from a DataView RRS feed

  • Question

  • My program is doing "foreach" processing against a DataView. I need to look ahead in the sequence without affecting the currently processed row.

    Is there an easy way to obtain the specific row being processed and then index into the DataView to get the one I need? Should I be using a method other than "foreach" to enumerate the rows?

    FWIW, order of the dataview and data type of the sequencing column(s) will vary between executions.

    Thanks in advance.

    • Moved by VMazurModerator Monday, January 4, 2010 11:09 AM (From:ADO.NET Data Providers)
    Tuesday, December 29, 2009 8:51 PM

Answers

  • Can't you use For...Next instead of For Each...Next? Counter would be the index of the relative position of the row in the DataView.

                For Counter As Integer = 0 To DataView.Count - 1
                    Console.WriteLine(DataView(Counter)("COL_NAME").ToString)
                Next
    


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by Tom Price Wednesday, December 30, 2009 11:09 PM
    Wednesday, December 30, 2009 9:35 PM

All replies

  • I believe that you can reference a specific row and column directly, by ordinal position, using the below syntax (i is row number and item is the column name or number).


    DataView(i)("item").ToString

    Paul ~~~~ Microsoft MVP (Visual Basic)
    Wednesday, December 30, 2009 5:28 PM
  • I'm good on that. But, is there a way to determine "i", given a specific DataRowView so that I can reference a relative row (i.e current row+10). The DataRowView is currently a parameter and the DataView is enumerated outside the module via a "foreach". Looking more and more like the caller would need to count the rows off and pass the ordinal row number too...

    Sorry for the newbie questions. Thanks in advance.
    Wednesday, December 30, 2009 7:18 PM
  • Can't you use For...Next instead of For Each...Next? Counter would be the index of the relative position of the row in the DataView.

                For Counter As Integer = 0 To DataView.Count - 1
                    Console.WriteLine(DataView(Counter)("COL_NAME").ToString)
                Next
    


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by Tom Price Wednesday, December 30, 2009 11:09 PM
    Wednesday, December 30, 2009 9:35 PM
  • Not what I hoped for but guess that's what it has to be. Thx.

    Wednesday, December 30, 2009 11:09 PM