voila tout le code :
using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
System.Data;
using
System.Data.SqlClient;
namespace
tp1
{
/// <summary>
/// Description résumée de Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
public System.Data.SqlClient.SqlConnection sqlConnection1;
private tp1.DataSet1 dataSet11;
private System.Windows.Forms.DataGrid dataGrid1;
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();
//
// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
//
}
/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region
Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet11 = new tp1.DataSet1();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(104, 32);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(104, 64);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(168, 96);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(32, 24);
this.button1.TabIndex = 2;
this.button1.Text = "ok";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "user", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("login", "login"),
new System.Data.Common.DataColumnMapping("password", "password")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM [user] WHERE (login = @Original_login) AND (password = @Original_pass" +
"word OR @Original_password IS NULL AND password IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_login", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "login", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_password", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "password", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=LACHGAR;packet size=4096;integrated security=SSPI;data source=lach" +
"gar;persist security info=False;initial catalog=test";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO [user] (login, password) VALUES (@login, @password); SELECT login, pa" +
"ssword FROM [user] WHERE (login = @login)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@login", System.Data.SqlDbType.VarChar, 10, "login"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@password", System.Data.SqlDbType.VarChar, 10, "password"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT login, password FROM [user]";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE [user] SET login = @login, password = @password WHERE (login = @Original_l" +
"ogin) AND (password = @Original_password OR @Original_password IS NULL AND passw" +
"ord IS NULL); SELECT login, password FROM [user] WHERE (login = @login)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@login", System.Data.SqlDbType.VarChar, 10, "login"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@password", System.Data.SqlDbType.VarChar, 10, "password"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_login", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "login", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_password", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "password", System.Data.DataRowVersion.Original, null));
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("fr-FR");
//
// dataGrid1
//
this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;
this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;
this.dataGrid1.BackgroundColor = System.Drawing.Color.LightGray;
this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.dataGrid1.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
this.dataGrid1.CaptionFont = new System.Drawing.Font("Microsoft Sans Serif", 8F);
this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
this.dataGrid1.DataMember = "user";
this.dataGrid1.DataSource = this.dataSet11;
this.dataGrid1.FlatMode = true;
this.dataGrid1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;
this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
this.dataGrid1.HeaderBackColor = System.Drawing.Color.MidnightBlue;
this.dataGrid1.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 8F);
this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
this.dataGrid1.Location = new System.Drawing.Point(152, 152);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
this.dataGrid1.Size = new System.Drawing.Size(208, 96);
this.dataGrid1.TabIndex = 3;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(384, 285);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
sqlInsertCommand1=new SqlCommand("INSERT INTO user(login,password) VALUES('foad','453788')",sqlConnection1);
sqlConnection1.Open();
sqlInsertCommand1.ExecuteNonQuery();
sqlConnection1.Close();
}
}
}