Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Lier ‘DataSet’ à un ‘TextBox’

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

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
using System.Configuration;
using System.Data.SqlClient;
 
public class TextBoxDataSet : Form
{
    public TextBoxDataSet() {
        InitializeComponent();
 
        DataSet dataSet = CreateDataSet();
 
        txtSociété.DataBindings.Add("Text", dataSet.Tables["Clients"], "Société");
    }
 
    private DataSet CreateDataSet() {
        string requête = "SELECT * FROM Clients";
        DataSet ds = new DataSet();
 
        using (SqlConnection con = new SqlConnection("server=(local);database=MesExemples.com;Integrated Security=SSPI"))
        {
            SqlDataAdapter da = new SqlDataAdapter(requête, con);
 
            da.Fill(ds, "Clients");
        }
 
        return ds;
    }
    private System.Windows.Forms.TextBox txtSociété;
    private void InitializeComponent() {
        this.txtSociété = new System.Windows.Forms.TextBox();
        this.SuspendLayout();
        //
        // txtSociété
        //
        this.txtSociété.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.txtSociété.Location = new System.Drawing.Point(12, 12);
        this.txtSociété.Name = "textBox1";
        this.txtSociété.Size = new System.Drawing.Size(370, 20);
        this.txtSociété.TabIndex = 0;
        //
        // TextBoxDataSet
        //
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(394, 44);
        this.Controls.Add(this.txtSociété);
        this.Name = "TextBoxDataSet";
        this.Text = "Liaison TextBox DataSet";
        this.ResumeLayout(false);
        this.PerformLayout();
 
    }
 
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new TextBoxDataSet());
    }
}

No comments yet.

Leave a Comment