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
| protected void insertion_donnee(object sender, EventArgs e)
{
string code = tb_codeCli.Text;
string nom = tb_nomCli.Text;
string prenom = tb_PnomCli.Text;
string login = tb_loginCli.Text;
string mdp = tb_mdpCli.Text;
string droit = tb_nivDroitCli.Text;
SqlConnection connexion = new SqlConnection(System.Configuration.ConfigurationManager.
ConnectionStrings["connectString1"].ConnectionString);
connexion.Open();
// requête Insert/Update des informations dans la table du mois en cours REPLACE autorisé avce MySql ;)
string query = "INSERT INTO personne value (@code, @nom, @prenom, @login, @mdp, @droit)";
using (SqlConnection Connection = new SqlConnection(System.Configuration.ConfigurationManager.
ConnectionStrings["connectString1"].ConnectionString))
{
SqlCommand cmdInsert = new SqlCommand(query, Connection);
// commande SQL insertion dans table
cmdInsert.CommandText = query;
// "paramètrage" des paramètres
cmdInsert.Parameters.Add("@code", SqlDbType.VarChar, 10); // Type à remplacer par le type adéquat
cmdInsert.Parameters.Add("@nom", SqlDbType.VarChar, 20); // Type à remplacer par le type adéquat
cmdInsert.Parameters.Add("@prenom", SqlDbType.VarChar, 20); // Type à remplacer par le type adéquat
cmdInsert.Parameters.Add("@login", SqlDbType.VarChar, 10); // Type à remplacer par le type adéquat
cmdInsert.Parameters.Add("@mdp", SqlDbType.VarChar, 5); // Type à remplacer par le type adéquat
cmdInsert.Parameters.Add("@droit", SqlDbType.VarChar, 1); // Type à remplacer par le type adéquat
// récupèration des valeurs des paramètres
cmdInsert.Parameters["@code"].Value = "" + code + ""; // val1 peut-être une variable
cmdInsert.Parameters["@nom"].Value = "" + nom + ""; // ...
cmdInsert.Parameters["@prenom"].Value = "" + prenom + "";
cmdInsert.Parameters["@login"].Value = "" + login + "";
cmdInsert.Parameters["@mdp"].Value = "" + mdp + "";
cmdInsert.Parameters["@droit"].Value = "" + droit + "";
// connexion
Connection.Open();
if (Connection.State == System.Data.ConnectionState.Open)
// si la connexion est ouverte
{
// et on fait l'insertion
cmdInsert.ExecuteNonQuery();
// fermeture connection
Connection.Close();
}
}
}
} |
Partager