Data Binding 4 : 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.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Database ADO.net » Data BindingScreenshots 
Data Binding 4

/*
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
{
    /// <summary>
    /// Summary description for DataBinding4.
    /// </summary>
    public class DataBinding4 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.DataGrid grdOrders;
    private System.Windows.Forms.DataGrid grdOrderDetails;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.ComboBox cbCust;
    private System.Windows.Forms.TextBox txtPhoneNo;
    private System.Windows.Forms.TextBox txtFaxNo;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.TextBox txtContact;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public DataBinding4()
        {
            //
            // 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"]);

      grdOrders.DataSource=ds;
      grdOrders.DataMember="Table.CustOrder";
      grdOrderDetails.DataSource=ds;
      grdOrderDetails.DataMember="Table.CustOrder.OrderDetail";

      cbCust.DataSource=ds;
      cbCust.DisplayMember="Table.CompanyName";
      txtContact.DataBindings.Add("Text",ds,"Table.ContactName");
      txtPhoneNo.DataBindings.Add("Text",ds,"Table.Phone");
      txtFaxNo.DataBindings.Add("Text",ds,"Table.Fax");
        }

        /// <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.grdOrders = new System.Windows.Forms.DataGrid();
      this.grdOrderDetails = new System.Windows.Forms.DataGrid();
      this.cbCust = new System.Windows.Forms.ComboBox();
      this.txtPhoneNo = new System.Windows.Forms.TextBox();
      this.txtFaxNo = new System.Windows.Forms.TextBox();
      this.label1 = new System.Windows.Forms.Label();
      this.label2 = new System.Windows.Forms.Label();
      this.label3 = new System.Windows.Forms.Label();
      this.label4 = new System.Windows.Forms.Label();
      this.txtContact = new System.Windows.Forms.TextBox();
      ((System.ComponentModel.ISupportInitialize)(this.grdOrders)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.grdOrderDetails)).BeginInit();
      this.SuspendLayout();
      // 
      // 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;
      // 
      // cbCust
      // 
      this.cbCust.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
      this.cbCust.Location = new System.Drawing.Point(21632);
      this.cbCust.Name = "cbCust";
      this.cbCust.Size = new System.Drawing.Size(24021);
      this.cbCust.TabIndex = 3;
      // 
      // txtPhoneNo
      // 
      this.txtPhoneNo.Location = new System.Drawing.Point(21696);
      this.txtPhoneNo.Name = "txtPhoneNo";
      this.txtPhoneNo.Size = new System.Drawing.Size(24020);
      this.txtPhoneNo.TabIndex = 4;
      this.txtPhoneNo.Text = "textBox1";
      // 
      // txtFaxNo
      // 
      this.txtFaxNo.Location = new System.Drawing.Point(216128);
      this.txtFaxNo.Name = "txtFaxNo";
      this.txtFaxNo.Size = new System.Drawing.Size(24020);
      this.txtFaxNo.TabIndex = 5;
      this.txtFaxNo.Text = "textBox2";
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(8032);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(12824);
      this.label1.TabIndex = 6;
      this.label1.Text = "Customer Name";
      this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
      // 
      // label2
      // 
      this.label2.Location = new System.Drawing.Point(8096);
      this.label2.Name = "label2";
      this.label2.Size = new System.Drawing.Size(12824);
      this.label2.TabIndex = 7;
      this.label2.Text = "Phone Number";
      this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
      // 
      // label3
      // 
      this.label3.Location = new System.Drawing.Point(80128);
      this.label3.Name = "label3";
      this.label3.Size = new System.Drawing.Size(12824);
      this.label3.TabIndex = 8;
      this.label3.Text = "Fax Number";
      this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
      // 
      // label4
      // 
      this.label4.Location = new System.Drawing.Point(8064);
      this.label4.Name = "label4";
      this.label4.Size = new System.Drawing.Size(12824);
      this.label4.TabIndex = 10;
      this.label4.Text = "Contact Name";
      this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
      // 
      // txtContact
      // 
      this.txtContact.Location = new System.Drawing.Point(21664);
      this.txtContact.Name = "txtContact";
      this.txtContact.Size = new System.Drawing.Size(24020);
      this.txtContact.TabIndex = 9;
      this.txtContact.Text = "textBox1";
      // 
      // DataBinding4
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(520483);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.label4,
                                                                  this.txtContact,
                                                                  this.label3,
                                                                  this.label2,
                                                                  this.label1,
                                                                  this.txtFaxNo,
                                                                  this.txtPhoneNo,
                                                                  this.cbCust,
                                                                  this.grdOrderDetails,
                                                                  this.grdOrders});
      this.Name = "DataBinding4";
      this.Text = "DataBinding4";
      ((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 DataBinding4());
        }
    }
}


           
       
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 3
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.