, Visual C#


ADO.NET


21.1. Customers .

private void button1_Click(object sender, EventArgs e)

{

DataSet myDataSet = new DataSet();

 

oleDbConnection1.Open();

 

oleDbDataAdapter1.Fill(myDataSet, "Customers");

oleDbDataAdapter2.Fill(myDataSet, "Orders");

oleDbDataAdapter3.Fill(myDataSet, "OrderDetails");

 

oleDbConnection1.Close();

 

dataGrid1.DataSource = myDataSet;

 

dataGrid1.DataMember = "Customers";

 

this.Text = "The table Customers is bound to DataSet"

"with no defined relationships";

}

Bind the table Customers to DataSet with relationships ( Customers ). Form1.cs , .

21.2. Customers .

private void button2_Click(object sender, EventArgs e)

{

DataSet myDataSet = new DataSet();

 

oleDbConnection1.Open();

 

oleDbDataAdapter1.Fill(myDataSet, "Customers");

oleDbDataAdapter2.Fill(myDataSet, "Orders");

oleDbDataAdapter3.Fill(myDataSet, "OrderDetails");

 

oleDbConnection1.Close();

myDataSet.Relations.Add("CustomerOrders",

myDataSet.Tables.

Item[S"Customers"].Columns.Item[S"customerID"],

myDataSet.Tables.Item[S"Orders"].

Columns.Item[S"customerID"]);

myDataSet.Relations.Add("OrderOrderDetails",

myDataSet.Tables.

Item[S"Orders"].Columns.Item["OrderID"],

myDataSet.Tables.Item[S"OrderDetails"].

Columns.Item[S"OrderID"]);

 

dataGrid1.DataSource = myDataSet;