Data Binding 3 : Data Binding « Database ADO.net « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Database ADO.net » Data BindingScreenshots 
Data Binding 3

/*
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 Disposebool disposing )
        {
            ifdisposing )
            {
                if (components != null
                {
                    components.Dispose();
                }
            }
            base.Disposedisposing );
        }

        #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(4016);
            this.grdCustomers.Name = "grdCustomers";
            this.grdCustomers.Size = new System.Drawing.Size(448152);
            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(40176);
            this.grdOrders.Name = "grdOrders";
            this.grdOrders.Size = new System.Drawing.Size(448144);
            this.grdOrders.TabIndex = 1;
            // 
            // grdOrderDetails
            // 
            this.grdOrderDetails.DataMember = "";
            this.grdOrderDetails.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.grdOrderDetails.Location = new System.Drawing.Point(40328);
            this.grdOrderDetails.Name = "grdOrderDetails";
            this.grdOrderDetails.Size = new System.Drawing.Size(448136);
            this.grdOrderDetails.TabIndex = 2;
            // 
            // DataBinding_3
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(513);
            this.ClientSize = new System.Drawing.Size(528483);
            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());
        }
    }
}

           
       
Related examples in the same category
1.ADO.NET Binding: Handling ErrorsADO.NET Binding: Handling Errors
2.ADO.NET Binding: Master DetailADO.NET Binding: Master Detail
3.ADO.NET Binding : Multiple Control BindingADO.NET Binding : Multiple Control Binding
4.ADO.NET Binding : UnsynchronizedADO.NET Binding : Unsynchronized
5.Data Binding 4
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.