Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Lier un Label à un ‘DataSet’

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

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
 
   public class DataSetLable: System.Windows.Forms.Form
   {
      private System.Windows.Forms.Label labelID;
      private System.Windows.Forms.Label labelSociété;
      private System.Data.DataSet dataSet1;
 
      public DataSetLable()
      { 
 
         InitializeComponent();
      }
 
      private void InitializeComponent() {
         this.labelID = new System.Windows.Forms.Label();
         this.labelSociété = new System.Windows.Forms.Label();
         this.dataSet1 = new System.Data.DataSet();
         ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
         this.SuspendLayout();
 
         this.labelID.Location = new System.Drawing.Point(16, 8);
         this.labelID.Name = "labelID";
         this.labelID.Size = new System.Drawing.Size(72, 16);
         this.labelID.TabIndex = 0;
         this.labelID.Text = "ID";
 
         this.labelSociété.Location = new System.Drawing.Point(16, 40);
         this.labelSociété.Name = "labelSociété";
         this.labelSociété.Size = new System.Drawing.Size(190, 60);
         this.labelSociété.TabIndex = 1;
         this.labelSociété.Text = "Société";
 
         this.dataSet1.DataSetName = "NewDataSet";
         this.dataSet1.Locale = new System.Globalization.CultureInfo("fr");
 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(128, 69);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.labelSociété,
                                                                      this.labelID});
         this.Name = "DataSetLable";
         this.Text = "Liaison DataSet et Label";
         this.Load += new System.EventHandler(this.Form1_Load);
         ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
         this.ResumeLayout(false);
 
      }
 
      static void Main() {
         Application.Run(new DataSetLable());
      }
 
      private void Form1_Load(object sender, System.EventArgs e) {
         string chaineConnexion= "server=(local);database=MesExemples.com;Integrated Security=SSPI";
 
         string requête = @"select ID, Société from Clients";
 
         SqlConnection Conn = new SqlConnection(chaineConnexion);
         SqlDataAdapter da = new SqlDataAdapter(requête, Conn);
 
         da.Fill(dataSet1, "Clients");
 
         // Afficher les ID des sociétés dans le Label1
         labelID.DataBindings.Add("Text", dataSet1, "Clients.ID");
         // Afficher les Noms des sociétés dans le Label2
         labelSociété.DataBindings.Add("Text", dataSet1, "Clients.Société");
      }
   }

No comments yet.

Leave a Comment