Solved

Stepping through a Dataset

Posted on 2002-06-07
2
420 Views
Last Modified: 2012-06-27
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
Comment
Question by:sonus
2 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 100 total points
ID: 7063763
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
 

Author Comment

by:sonus
ID: 7063888
Thanks, that's exactly the code I was looking for.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question