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
|
public partial class Form1 : Form
{
private OleDbConnection connection = new OleDbConnection();
public Form1()
{
InitializeComponent();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\USER\Documents\Visual Studio 2010\Projects\Perso\GA2P.mdb;
Persist Security Info=False;";
}
private void button1_Click(object sender, EventArgs e)
{
string marequête;
string marequête1;
try
{
marequête="Insert into AGENT(Matricule,Nom_Prénom,Date_naiss,Lieu_naiss,Age,Sexe,Situation_matrimon,Type_agent,Corps,Cadre,CATEGORIE,Grade,Echelon,Adresse,Personne_à_contacter) values(@textBox1,@textBox2,@dateTimePicker1,@textBox8,@textBox5,@comboBox1,@comboBox2,@comboBox3,@textBox3,@textBox6,@comboBox4,@comboBox5,@comboBox6,@textBox4,@textBox7)";
OleDbCommand command = new OleDbCommand(marequête,connection);
command.Connection = connection;
comboBox1.SelectedIndex = 0;
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("?textBox1",textBox1.Text);
command.Parameters.AddWithValue("?textBox2", textBox2.Text);
command.Parameters.AddWithValue("?dateTimePicker1", dateTimePicker1.Value);
command.Parameters.AddWithValue("?textBox8", textBox8.Text);
command.Parameters.AddWithValue("?textBox5", textBox5.Text);
command.Parameters.AddWithValue("?comboBox1", comboBox1.SelectedValue);
command.Parameters.AddWithValue("?comboBox2", comboBox2.SelectedValue);
command.Parameters.AddWithValue("?comboBox3", comboBox3.SelectedValue);
command.Parameters.AddWithValue("?textBox3", textBox3.Text);
command.Parameters.AddWithValue("?textBox6", textBox6.Text);
command.Parameters.AddWithValue("?comboBox4", comboBox4.SelectedValue);
command.Parameters.AddWithValue("?comboBox5", comboBox5.SelectedValue);
command.Parameters.AddWithValue("?comboBox6", comboBox6.SelectedValue);
command.Parameters.AddWithValue("?textBox4", textBox4.Text);
command.Parameters.AddWithValue("?textBox7", textBox7.Text);
command.Connection.Open();
command.ExecuteNonQuery();
command.Connection.Close();
marequête1 = "insert into SERVICE(Direction,Service,Fonction,Date affectation) values(@textBox9,@ textBox10,@textBox11,@textBox12)";
OleDbCommand command1 = new OleDbCommand(marequête1, connection);
command1.Connection = connection;
command1.Parameters.AddWithValue("@textBox9", textBox9.Text);
command1.Parameters.AddWithValue("@textBox10", textBox10.Text);
command1.Parameters.AddWithValue("@textBox11", textBox11.Text);
command1.Parameters.AddWithValue("@textBox12", textBox12.Text);
command1.Connection.Open();
command1.ExecuteNonQuery();
command1.Connection.Close();
}
catch (OleDbException ex)
{
MessageBox.Show("Erreur" + ex);
} |
Partager