• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

Stepping through a Dataset

As dumb as this question seems, I can't seem to find the answer in any of my books or online help.  I know I can use a DataReader to step through a result set, but what if I was given a dataset?  What is the code needed to step through it row by row?

0
sonus
Asked:
sonus
1 Solution
 
naveenkohliCommented:
DataSet has Tables property. Table has Rows property and Row has Columns property. You just need to make use of thiese properties to get the values.

Here is sample from documentation.

private void PrintRows(DataSet myDataSet){
   // For each table in the DataSet, print the row values.
   foreach(DataTable myTable in myDataSet.Tables){
      foreach(DataRow myRow in myTable.Rows){
         foreach (DataColumn myColumn in myTable.Columns){
            Console.WriteLine(myRow[myColumn]);
         }
      }
   }
}

Private Sub PrintRows(ByVal myDataSet As DataSet)
   Dim myTable As DataTable
   Dim myRow As DataRow
   Dim myColumn As DataColumn
   ' For each table in the DataSet, print the row values.
   For Each myTable in myDataSet.Tables
      For Each myRow In myTable.Rows
         For Each myColumn in myTable.Columns
            Console.WriteLine(myRow(myColumn))
         Next myColumn
      Next myRow
   Next myTable
End Sub

0
 
sonusAuthor Commented:
Thanks, that's exactly the code I was looking for.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now