/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow
Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace DataBinding_3
{
/// <summary>
/// Summary description for DataBinding_3.
/// </summary>
public class DataBinding_3 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid grdOrders;
private System.Windows.Forms.DataGrid grdOrderDetails;
private System.Windows.Forms.DataGrid grdCustomers;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public DataBinding_3()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
SqlConnection cn=new SqlConnection(@"data source=(local);uid=sa;password=;database=northwind");
DataSet ds = new DataSet("CustOrders");
SqlDataAdapter daCust=new SqlDataAdapter("select * from customers;select * from orders;select * from [order details]",cn);
daCust.Fill(ds);
ds.Relations.Add("CustOrder",ds.Tables["Table"].Columns["customerid"],ds.Tables["Table1"].Columns["customerid"]);
ds.Relations.Add("OrderDetail",ds.Tables["Table1"].Columns["orderid"],ds.Tables["Table2"].Columns["orderid"]);
grdCustomers.DataSource=ds;
grdCustomers.DataMember="Table";
grdOrders.DataSource=ds;
grdOrders.DataMember="Table.CustOrder";
grdOrderDetails.DataSource=ds;
grdOrderDetails.DataMember="Table.CustOrder.OrderDetail";
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.grdCustomers = new System.Windows.Forms.DataGrid();
this.grdOrders = new System.Windows.Forms.DataGrid();
this.grdOrderDetails = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.grdCustomers)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.grdOrders)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.grdOrderDetails)).BeginInit();
this.SuspendLayout();
//
// grdCustomers
//
this.grdCustomers.AllowNavigation = false;
this.grdCustomers.DataMember = "";
this.grdCustomers.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.grdCustomers.Location = new System.Drawing.Point(40, 16);
this.grdCustomers.Name = "grdCustomers";
this.grdCustomers.Size = new System.Drawing.Size(448, 152);
this.grdCustomers.TabIndex = 0;
//
// grdOrders
//
this.grdOrders.AllowNavigation = false;
this.grdOrders.DataMember = "";
this.grdOrders.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.grdOrders.Location = new System.Drawing.Point(40, 176);
this.grdOrders.Name = "grdOrders";
this.grdOrders.Size = new System.Drawing.Size(448, 144);
this.grdOrders.TabIndex = 1;
//
// grdOrderDetails
//
this.grdOrderDetails.DataMember = "";
this.grdOrderDetails.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.grdOrderDetails.Location = new System.Drawing.Point(40, 328);
this.grdOrderDetails.Name = "grdOrderDetails";
this.grdOrderDetails.Size = new System.Drawing.Size(448, 136);
this.grdOrderDetails.TabIndex = 2;
//
// DataBinding_3
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(528, 483);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.grdOrderDetails,
this.grdOrders,
this.grdCustomers});
this.Name = "DataBinding_3";
this.Text = "DataBinding_3";
((System.ComponentModel.ISupportInitialize)(this.grdCustomers)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.grdOrders)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.grdOrderDetails)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new DataBinding_3());
}
}
}
|