Solved

Stepping through a Dataset

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now