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
|
private void util_added(WindowsFormsApplication1.form_addutil.Ident identif)
{
// On à récupérer les champs utilisateurs à insérer dans la base
string ConnectionStr = "Database=aide_au_depannage;Data Source=localhost;User Id=root;Password=''";
Connection.ConnectionString = ConnectionStr;
Connection.Open();
try
{
// Requete parametrée
string Requete = "INSERT INTO identification(ident,mot_de_passe) VALUES (?ident,?mot_de_passe)";//; select LAST_INSERT_ID() as UserID;";
// On associe cette requête à la propriété SelectCommand du MySqlDataAdapter
MyAdapter.SelectCommand = new MySqlCommand(Requete, Connection);
//Création et déclaration des paramètres
MySqlParameter myparamident = new MySqlParameter("?ident", MySqlDbType.Char, 30);
MySqlParameter myparammdp = new MySqlParameter("?mot_de_passe", MySqlDbType.Char, 30);
//Attribution des valeurs aux paramètres
myparamident.Value = identif.identifiant;
myparammdp.Value = identif.MdP;
MyAdapter.SelectCommand.Parameters.Add(myparamident);
MyAdapter.SelectCommand.Parameters.Add(myparammdp);
MyAdapter.SelectCommand.ExecuteNonQuery();
}
catch (Exception ex1)
{
TxtBoxMain.AppendText(ex1.Message);
}
Connection.Close();
} |