Probleme avec mon code

Assad76 Messages postés 2 Date d'inscription mercredi 19 novembre 2014 Statut Membre Dernière intervention 21 novembre 2014 - Modifié par Whismeril le 19/11/2014 à 22:30
Assad76 Messages postés 2 Date d'inscription mercredi 19 novembre 2014 Statut Membre Dernière intervention 21 novembre 2014 - 21 nov. 2014 à 09:25
Salut!

Je suis nouveau sur ce forum,je suis entrain de concevoir une bdd gestion du personnel
j'utilise Access comme SGBD lequel j'ai importé sur c#

Now mon problème : je n'arrive pas dans un form contenant les champs de deux tables à enregistrer les données grâce à un bouton Save:

Pour celui qui veut bien jeter un coup d'oeil voici mon code :


 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)
        {
           
           
            try
            {
                
                OleDbCommand command = new OleDbCommand();
                
                command.Connection = connection;
                command.Connection.Open();
                 
                 
                command.CommandText="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(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                command.CommandType = CommandType.Text;
                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.ExecuteNonQuery();
                command.Connection.Close(); 

                
                OleDbCommand command1 = new OleDbCommand();
             
                command1.Connection = connection;
                command1.Connection.Open();
                
                command1.CommandText= "insert into SERVICE(Direction,Service,Fonction,Date affectation) values(?,?,?,?)";
                command1.CommandType = CommandType.Text;
                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.ExecuteNonQuery();
                       
                command1.Connection.Close();

                }

                catch (OleDbException ex)
            {
                MessageBox.Show("Erreur" + ex);
            }

1 réponse

jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 344
19 nov. 2014 à 18:54
Bonjour,
je n'arrive pas

.. tu peux détailler ?
Tu as un message d'erreur ? si oui.. lequel ?
Tu as testé séparément chaque insertion ? ( elles fonctionnent ?)
Si ton souci se situe au niveaux des requêtes... les as tu testé en Base directement pour savoir si elles sont bonnes ?


0
Assad76 Messages postés 2 Date d'inscription mercredi 19 novembre 2014 Statut Membre Dernière intervention 21 novembre 2014
21 nov. 2014 à 09:25
Bonjour Jordane!

Quand je clique sur le bouton Save séparérement ça marche pour la deuxième Insert mais par contre l'autre Insert m'affiche ce message :
Le paramètre @comboBox1 n'as pas de valeur par défaut
0
Rejoignez-nous