Exemple de liaison de données avec ADO.Net

Author:

Recherche,dans,la,base,de,données:,non,édité
{filelink=16133}

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Base_de_Données
{

    public class BDXML : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.GroupBox groupeBox;
        internal System.Windows.Forms.ListBox listEntrepises;
        internal System.Windows.Forms.GroupBox groupeBoxEse;
        internal System.Windows.Forms.ListBox listEntreprise;

        private System.ComponentModel.Container components = null;

        public BDXML()
        {

            InitializeComponent();

        }

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        ///

        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// 

        private void InitializeComponent()
        {
            this.groupeBox = new System.Windows.Forms.GroupBox();
            this.listEntrepises = new System.Windows.Forms.ListBox();
            this.groupeBoxEse = new System.Windows.Forms.GroupBox();
            this.listEntreprise = new System.Windows.Forms.ListBox();
            this.groupeBox.SuspendLayout();
            this.groupeBoxEse.SuspendLayout();
            this.SuspendLayout();
            //
            // grp
            //
            this.groupeBox.Controls.Add(this.listEntrepises);
            this.groupeBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.groupeBox.Location = new System.Drawing.Point(6, 137);
            this.groupeBox.Name = "grp";
            this.groupeBox.Size = new System.Drawing.Size(280, 136);
            this.groupeBox.TabIndex = 5;
            this.groupeBox.TabStop = false;
            //
            // listEntrepises
            //
            this.listEntrepises.Location = new System.Drawing.Point(16, 24);
            this.listEntrepises.Name = "listEntrepises";
            this.listEntrepises.Size = new System.Drawing.Size(248, 95);
            this.listEntrepises.TabIndex = 1;
            //
            // grpCategory
            //
            this.groupeBoxEse.Controls.Add(this.listEntreprise);
            this.groupeBoxEse.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.groupeBoxEse.Location = new System.Drawing.Point(6, 0);
            this.groupeBoxEse.Name = "grpCategory";
            this.groupeBoxEse.Size = new System.Drawing.Size(280, 136);
            this.groupeBoxEse.TabIndex = 4;
            this.groupeBoxEse.TabStop = false;
            //
            // listEntreprise
            //
            this.listEntreprise.Location = new System.Drawing.Point(16, 24);
            this.listEntreprise.Name = "listEntreprise";
            this.listEntreprise.Size = new System.Drawing.Size(248, 95);
            this.listEntreprise.TabIndex = 0;
            //
            // BDXML
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(300, 290);
            this.Controls.Add(this.groupeBox);
            this.Controls.Add(this.groupeBoxEse);
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Name = "BDXML";
            this.Text = "BDXML";
            this.Load += new System.EventHandler(this.BDXML_Load);
            this.groupeBox.ResumeLayout(false);
            this.groupeBoxEse.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion

        private void BDXML_Load(object sender, System.EventArgs e)
        {
            groupeBoxEse.BindingContext = new BindingContext();

            DataSet dsStore = new DataSet();
            dsStore.ReadXmlSchema(Application.StartupPath + @"Clients.xsd");
            dsStore.ReadXml(Application.StartupPath + @"Clients.xml");

            listEntreprise.DataSource = dsStore.Tables["Clients"];
            listEntreprise.DisplayMember = "Entreprise";

            listEntrepises.DataSource = dsStore.Tables["Clients"];
            listEntrepises.DisplayMember = "Nom-Contact";
        }

        [STAThread]
        static void Main()
        {
            Application.Run(new BDXML());
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *