Solved

Stepping through a Dataset

Posted on 2002-06-07
2
418 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

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