Cómo: Crear mediante programación un objeto de conjunto de datos jerárquicos con ADO.NET en Visual Basic .NET

Imports System
Imports System.Data
Imports System.XML

 

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())

http://support2.microsoft.com/kb/316260/es