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
| private void add_Click(object sender, EventArgs e)
{
//on vérifi que tout les champs sont remplis
if ((textBox1.Text == "") ||( textBox2.Text == "") ||(textBox3.Text == ""))
{
MessageBox.Show("Veuillez remplir tout les champs oblibatoires");
}
else
{
// Open connection
using (SqlConnection con = new SqlConnection(Properties.Settings.Default.mabaseConnectionString))
con.Open();
SqlCommand cmd = new SqlCommand("Insert Into patient(Matricule, Nom, Prenom, DateNaissance, Tel) Values (@Mat,@Nom,@Pre,@Dat,@Tel)", con);
cmd.Parameters.AddWithValue("Mat", textBox1.Text);
cmd.Parameters.AddWithValue("Nom", textBox2.Text);
cmd.Parameters.AddWithValue("Pre", textBox3.Text);
cmd.Parameters.AddWithValue("Dat", dateTimePicker1.Text);
cmd.Parameters.AddWithValue("Tel", textBox4.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Inserted sucessfully");
}
} |
Partager