George,
Können Sie bitte Ihre Frage klären - ist es etwa mulitple Tabellen in Dataset füllen oder speziell reelle Tabellen.
Für mehrere Tabellen Laden betrifft Sie folgenden Code verweisen können (dieser Code ist bei MSDN http://msdn.microsoft.com/en-us/library/5fd1ahe2.aspx avialable):
static void Main()
{
DataSet dataSet = new DataSet();
DataTable customerTable = new DataTable();
DataTable productTable = new DataTable();
// This information is cosmetic, only.
customerTable.TableName = "Customers";
productTable.TableName = "Products";
// Add the tables to the DataSet:
dataSet.Tables.Add(customerTable);
dataSet.Tables.Add(productTable);
// Load the data into the existing DataSet.
DataTableReader reader = GetReader();
dataSet.Load(reader, LoadOption.OverwriteChanges,
customerTable, productTable);
// Print out the contents of each table:
foreach (DataTable table in dataSet.Tables)
{
PrintColumns(table);
}
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
private static DataTable GetCustomers()
{
// Create sample Customers table.
DataTable table = new DataTable();
table.TableName = "Customers";
// Create two columns, ID and Name.
DataColumn idColumn = table.Columns.Add("ID", typeof(int));
table.Columns.Add("Name", typeof(string));
// Set the ID column as the primary key column.
table.PrimaryKey = new DataColumn[] { idColumn };
table.Rows.Add(new object[] { 0, "Mary" });
table.Rows.Add(new object[] { 1, "Andy" });
table.Rows.Add(new object[] { 2, "Peter" });
table.AcceptChanges();
return table;
}
private static DataTable GetProducts()
{
// Create sample Products table.
DataTable table = new DataTable();
table.TableName = "Products";
// Create two columns, ID and Name.
DataColumn idColumn = table.Columns.Add("ID",
typeof(int));
table.Columns.Add("Name", typeof(string));
// Set the ID column as the primary key column.
table.PrimaryKey = new DataColumn[] { idColumn };
table.Rows.Add(new object[] { 0, "Wireless Network Card" });
table.Rows.Add(new object[] { 1, "Hard Drive" });
table.Rows.Add(new object[] { 2, "Monitor" });
table.Rows.Add(new object[] { 3, "CPU" });
table.AcceptChanges();
return table;
}
private static void PrintColumns(DataTable table)
{
Console.WriteLine();
Console.WriteLine(table.TableName);
Console.WriteLine("=========================");
// Loop through all the rows in the table:
foreach (DataRow row in table.Rows)
{
for (int i = 0; i < table.Columns.Count; i++)
{
Console.Write(row[i] + " ");
}
Console.WriteLine();
}
}
private static DataTableReader GetReader()
{
// Return a DataTableReader containing multiple
// result sets, just for the sake of this demo.
DataSet dataSet = new DataSet();
dataSet.Tables.Add(GetCustomers());
dataSet.Tables.Add(GetProducts());
return dataSet.CreateDataReader();
}
Hier ist der Code Eltern-Kind-Beziehung für die Verwaltung der Daten
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class DataRelation
Inherits System.Web.UI.Page
Protected lblDisplay As System.Web.UI.WebControls.Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objConn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim dtrParent As DataRow
Dim dtrChild As DataRow
objConn = New SqlConnection(ConfigurationSettings.Appsettings("NorthwindConnection"))
da = New SqlDataAdapter("SELECT * FROM Categories", objConn)
ds = New DataSet()
Try
objConn.Open()
da.Fill(ds,"Categories")
da.SelectCommand = New SqlCommand("SELECT * FROM Products", objConn)
da.Fill(ds, "Products")
Catch exc As SqlException
Response.Write(exc.ToString())
Finally
objConn.Dispose()
End Try
'Create the Data Relationship
ds.Relations.Add("Cat_Prod",ds.Tables("Categories").Columns("CategoryID"), _
ds.Tables("Products").Columns("CategoryID"))
'Display the Category and Child Products Within
For each dtrParent in ds.Tables("Categories").Rows
lblDisplay.Text &= "<h3>" & dtrParent("CategoryName") & "</h3><ul>"
For each dtrChild in dtrParent.GetChildRows("Cat_Prod")
lblDisplay.Text &= "<li>" & dtrChild("ProductName") & "</li>"
Next
lblDisplay.Text &= "</ul>"
Next
End Sub
End Class
setzt
Sie weitere Erklärung über here finden
Wenn Tabelle Customers und Orders-Tabelle Fremdschlüsselbeziehungen hat, werden die Beziehungen in dsTables.Tables gehalten werden (0) und dsTables.Tables (2)? – George2
BTW: Ich habe Ihre Probe gelesen, und die dsTables ist eine Art von was? Und wie kann ich die dsTables.Tables-Eigenschaft dsTables zuweisen? – George2
dsTables ist Dataset, sorry für die Verwirrung :( – Anuraj