.NET
  Home arrow .NET arrow Page 3 - An introduction to ADO.NET concluded
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

An introduction to ADO.NET concluded
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 12
    2006-01-05

    Table of Contents:
  • An introduction to ADO.NET concluded
  • ADO.NET datasets
  • The dataset classes
  • Concurrency and the disconnected data architecture

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    An introduction to ADO.NET concluded - The dataset classes


    (Page 3 of 4 )



    Figure 2-7 presents some of the properties and methods of the four main classes that you use to work with a dataset: DataSet, DataTable, DataColumn, and DataRow. As you saw in the previous figure, the objects you create from these classes form a hierarchy where each dataset can contain one or more tables and each table can contain one or more rows and one or more columns. Because of that, a dataset contains a Tables property that provides access to the collection of tables in the dataset. Similarly, a data table contains a Columns property and a Rows property that provide access to the collections of columns and rows in the table. These are the properties you’re most likely to use as you work with these objects.

    Although they’re not shown in this figure, the collections you refer to through the Tables property of a dataset and the Columns and Rows properties of a data table have properties and methods of their own. For instance, each collection has a Count property that you can use to determine how many items are in the collection. To get the number of tables in a dataset named dsPayables, for example, you could use code like this:

      dsPayables.Tables.Count()

    To access a specific item in a collection, you use the Item property. On that property, you specify the index value or name of the item you want to access. To access the Vendors table in the dsPayables dataset, for example, you can use code like this:

      dsPayables.Tables.Item("Vendors")

    Since Item is the default property of the collection class, however, you typically omit it like this:

      dsPayables.Tables("Vendors")

    The code in this figure shows how you can use a For Each…Next statement to loop through the items in a collection. Here, the statement loops through the rows in the Vendors table. To do that, it uses a variable that’s declared as a DataRow object. Then, the For Each…Next statement uses this variable to retrieve the value of the VendorName column in each row. You can use similar code to loop through the columns in a table or the tables in a dataset.

    Figure 2-7.  The DataSet, DataTable, DataColumn, and 
                            DataRow classes

    Common properties and methods of the DataSet class

    Common properties and methods of the DataTable class

    Common properties and methods of the DataColumn class

    Common properties and methods of the DataRow class

    Code that refers to the rows collection in the tables collection of a dataset

      Dim sMsg As String, dr As DataRow
      For Each dr In dsVendors.Tables("Vendors").Rows
         
    sMsg &= dr.Item("VendorName") & ControlChars.CrLf
      Next
      MessageBox.Show(sMsg)

    Description

    • You’ll use the properties and methods of the dataset classes most often when you work with ADO.NET objects through code, as described in chapter 6.
    • Each collection of objects has properties and methods that you can use to work with the collection.

       

    More .NET Articles
    More By Murach Publishing


       · This article is an excerpt from the book "VB.NET Database Programming with ADO.NET,"...
       · how to avoid concurency in dataset by using ds.timestamp
     

    Buy this book now. This article is excerpted from chapter two of the book VB.NET Database: Database Programming with ADO.NET, written by Anne Prince and Doug Lowe (Murach Publishing; ISBN: 1890774197). Check it out today at your favorite bookstore. Buy this book now.

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT