1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
public string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["csVinotheque"].ConnectionString;
}
private void ExecuteInsert( string nom, string adresse, string ville, string codepostal, string pays, string telephone, string email, string pseudo, string password)
{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO clients ( nom , adresse, ville, codepostal, pays, telephone, email, pseudo, password) VALUES "
+ " (@nom,@adresse,@ville,@codepostal,@pays,@telephone,@email,@pseudo,@password)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[9];
//param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
param[0] = new SqlParameter("@nom", SqlDbType.NChar, 20);
param[1] = new SqlParameter("@adresse", SqlDbType.NChar, 120);
param[2] = new SqlParameter("@ville", SqlDbType.NChar, 64);
param[3] = new SqlParameter("@codepostal", SqlDbType.NChar, 32);
param[4] = new SqlParameter("@pays", SqlDbType.NChar, 32);
param[5] = new SqlParameter("@telephone", SqlDbType.NChar, 32);
param[6] = new SqlParameter("@email", SqlDbType.NChar, 64);
param[7] = new SqlParameter("@pseudo", SqlDbType.VarChar, 50);
param[8] = new SqlParameter("@password", SqlDbType.VarChar, 50);
param[0].Value = nom;
param[1].Value = adresse;
param[2].Value = ville;
param[3].Value = codepostal;
param[4].Value = pays;
param[5].Value = telephone;
param[6].Value = email;
param[7].Value = pseudo;
param[8].Value = password;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
}
finally
{
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if ((pse.Text != "") && (pas.Text != "") && (nom.Text != "") && (adr.Text != "") && (vil.Text != "") && (cp.Text != "") && (pay.Text != "") && (tel.Text != "") && (mail.Text != ""))
{
ExecuteInsert(nom.Text, adr.Text, vil.Text, cp.Text, pay.Text, tel.Text, mail.Text, pse.Text, pas.Text);
Response.Redirect("Identification.aspx");
}
else
{
Label2.Visible = true;
}
} |
Partager