Navigation dans une base de données à l’aide de ‘BindingManagerBase’

Author:

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

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

namespace Base_de_données
{
  public class ExempleBindingManagerBase : System.Windows.Forms.Form
  {
      private System.Windows.Forms.TextBox txtID;
      private System.Windows.Forms.TextBox txtSociete;
      private System.Windows.Forms.Button btnPrec;
      private System.Windows.Forms.Button btnSuiv;
      private System.Data.DataSet dataSet1;
      private System.ComponentModel.Container components = null;
      private TextBox txtAdresse;

      private BindingManagerBase bMgr;

      public ExempleBindingManagerBase() {
        InitializeComponent();
      }

      private void InitializeComponent() {
this.txtID = new System.Windows.Forms.TextBox();
this.txtSociete = new System.Windows.Forms.TextBox();
this.btnPrec = new System.Windows.Forms.Button();
this.btnSuiv = new System.Windows.Forms.Button();
this.dataSet1 = new System.Data.DataSet();
this.txtAdresse = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
this.SuspendLayout();
//
// txtID
//
this.txtID.Location = new System.Drawing.Point(8, 8);
this.txtID.Name = "txtID";
this.txtID.Size = new System.Drawing.Size(160, 20);
this.txtID.TabIndex = 0;
//
// txtSociete
//
this.txtSociete.Location = new System.Drawing.Point(8, 40);
this.txtSociete.Name = "txtSociete";
this.txtSociete.Size = new System.Drawing.Size(160, 20);
this.txtSociete.TabIndex = 1;
//
// btnPrec
//
this.btnPrec.Location = new System.Drawing.Point(12, 108);
this.btnPrec.Name = "btnPrec";
this.btnPrec.Size = new System.Drawing.Size(56, 23);
this.btnPrec.TabIndex = 2;
this.btnPrec.Text = "<< Prec"; this.btnPrec.Click += new System.EventHandler(this.buttonBack_Click); // // btnSuiv // this.btnSuiv.Location = new System.Drawing.Point(92, 108); this.btnSuiv.Name = "btnSuiv"; this.btnSuiv.Size = new System.Drawing.Size(56, 23); this.btnSuiv.TabIndex = 3; this.btnSuiv.Text = "Suiv>>";
this.btnSuiv.Click += new System.EventHandler(this.buttonNext_Click);
//
// dataSet1
//
this.dataSet1.DataSetName = "UneDataSet";
this.dataSet1.Locale = new System.Globalization.CultureInfo("en-US");
//
// txtAdresse
//
this.txtAdresse.Location = new System.Drawing.Point(8, 67);
this.txtAdresse.Name = "txtAdresse";
this.txtAdresse.Size = new System.Drawing.Size(159, 20);
this.txtAdresse.TabIndex = 4;
//
// ExempleBindingManagerBase
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(180, 132);
this.Controls.Add(this.txtAdresse);
this.Controls.Add(this.btnSuiv);
this.Controls.Add(this.btnPrec);
this.Controls.Add(this.txtSociete);
this.Controls.Add(this.txtID);
this.Name = "ExempleBindingManagerBase";
this.Text = "Exemple BindingManagerBase";
this.Load += new System.EventHandler(this.ExempleBindingManagerBase_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

      }

      static void Main() {
         Application.Run(new ExempleBindingManagerBase());
      }

      private void ExempleBindingManagerBase_Load(object sender, System.EventArgs e) {
         string chaîneConnexion = @"server=(local);database=MesExemples.com;Integrated Security=SSPI";
         string requete = "select * from Clients ";

         SqlConnection conn = new SqlConnection(chaîneConnexion);
         SqlDataAdapter da = new SqlDataAdapter(requete, conn);
         da.Fill(dataSet1, "Clients");

         txtID.DataBindings.Add("text", dataSet1, "Clients.ID");
         txtAdresse.DataBindings.Add("text", dataSet1, "Clients.Adresse");
         txtSociete.DataBindings.Add("text", dataSet1, "Clients.Société");

         bMgr = this.BindingContext[dataSet1, "Clients"];
      }

      private void buttonNext_Click(object sender, System.EventArgs e) {
         bMgr.Position += 1;
      }

      private void buttonBack_Click(object sender, System.EventArgs e) {
         bMgr.Position -= 1;
      }
    }

}

Leave a Reply

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