Microsoft Knowledge Base Email Alertz

KBAlertz.com: (316260) - This step-by-step article describes how to create a hierarchical DataSet object that you can use as a structure for your programs. You may not have the exact data or structure that you want to use for your project. You can use the method in this...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 316260 - Last Review: August 14, 2006 - Revision: 3.0

HOW TO: Programmatically Create a Hierarchical DataSet Object with ADO.NET in Visual Basic .NET

This article was previously published under Q316260

On This Page

SUMMARY

This step-by-step article describes how to create a hierarchical DataSet object that you can use as a structure for your programs. You may not have the exact data or structure that you want to use for your project. You can use the method in this article to create prototypes for your examples. It may also be easier to submit only the data that you do have to the database without using the shape command syntax to send the data to the database. You might also have a limited set of data that you must add to the database. Instead of passing 20 arguments about the data to a method, you can pass the programmatically created DataSet object. This article describes how to use this method.

This example in this article creates a new customer and creates related order information, and outputs the data as XML. You start by defining the DataSet object, and then create two tables and a row. Then, you define the columns, add a relationship between the tables, fill the rows with data, append rows to the rows collection, and present the data in XML format.

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
  • Microsoft Visual Studio .NET installed on a compatible Microsoft Windows operating system
This article assumes that you are familiar with the following topics:
  • Visual Basic .NET
  • ADO.NET data access

Create the Project

  1. Start Visual Studio .NET, and then create a new Visual Basic .NET Console application.
  2. Add the following IMPORTS statements to the top of the code window:
    Imports System
    Imports System.Data
    Imports System.XML
    					
  3. In the Sub Main section, add the following code:
     
            Dim myDS As New Data.DataSet("CusOrd")
            Dim myCustomers As Data.DataTable = myDS.Tables.Add("Customers")
            Dim myOrders As Data.DataTable = myDS.Tables.Add("Orders")
            Dim myDr As Data.DataRow
    
            With myCustomers
                .Columns.Add("CustomerID", Type.GetType("System.String"))
                .Columns.Add("CompanyName", Type.GetType("System.String"))
                .Columns.Add("ContactName", Type.GetType("System.String"))
            End With
    
            With myOrders
                .Columns.Add("OrderID", Type.GetType("System.Int32"))
                .Columns.Add("CustomerID", Type.GetType("System.String"))
                .Columns.Add("EmployeeID", Type.GetType("System.Int32"))
                .Columns.Add("OrderDate", Type.GetType("System.DateTime"))
                .Columns.Add("RequiredDate", Type.GetType("System.DateTime"))
            End With
    
    
            myDS.Relations.Add("rel_Customers_Orders", _
            myDS.Tables("Customers").Columns("CustomerID"), _
            myDS.Tables("Orders").Columns("CustomerID"))
    
            myDr = myCustomers.NewRow()
            myDr("CustomerID") = "9876"
            myDr("CompanyName") = "Lucerne Publishing"
            myDr("ContactName") = "Kim Ralls"       
    
            myCustomers.Rows.Add(myDr)
    
            myDr = myOrders.NewRow()
            myDr("OrderID") = 6521
            myDr("CustomerID") = "9876"
            myDr("EmployeeID") = 852
            myDr("OrderDate") = #1/5/2002#
            myDr("RequiredDate") = #2/1/2002#
            myOrders.Rows.Add(myDr)
    
            Console.WriteLine(myDS.GetXml())
    					
  4. Press CTRL+F5 to run the application and observe the output.

REFERENCES

For additional information about how to populate a DataSet object in Visual Basic .NET, click the article number below to view the article in the Microsoft Knowledge Base:
301216  (http://kbalertz.com/Feedback.aspx?kbNumber=301216/EN-US/ ) HOW TO: Populate a DataSet Object from a Database by Using Visual Basic .NET

APPLIES TO
  • Microsoft ADO.NET 1.1
  • Microsoft ADO.NET 1.0
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
Keywords: 
kbhowtomaster kbsystemdata KB316260
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please