myCommand.CommandText = "INSERT INTO Produit (Nom) VALUES ('" + textBox1.Text + "')";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "INSERT INTO Produit (Nom) VALUES (@NomProduit)"; myCommand.Parameters.Add(new SqlParameter("@NomProduit", textBox1.Text)); myCommand.ExecuteNonQuery();
SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = "server=***;user=***;password=***;initial catalog=***"; myConnection.Open(); try { SqlCommand myCommand = new SqlCommand(); /* myCommand.CommandText = ("INSERT INTO Produit (Nom) VALUES ('"+textBox1.Text+"')"); */ myCommand.CommandText = "INSERT INTO Produit (Nom) VALUES (@NomProduit)"; myCommand.Parameters.Add(new SqlParameter("@NomProduit", textBox1.Text)); myCommand.ExecuteNonQuery(); MessageBox.Show("Produit Ajouté", "OK"); } catch (SqlException exp) { MessageBox.Show(exp.Message); } finally { myConnection.Close(); }
myCommand.Connection = myConnection;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question