Problème lors de l'ajout de données

juninho2lyon Messages postés 26 Date d'inscription vendredi 12 septembre 2008 Statut Membre Dernière intervention 8 mars 2009 - 25 févr. 2009 à 11:00
maladebe Messages postés 18 Date d'inscription jeudi 8 mai 2003 Statut Membre Dernière intervention 27 mars 2009 - 25 févr. 2009 à 11:41
Bonjour

je suis en train de créer une application en C# utilisant une base de données Access.

Or quand je clique sur le bouton "ajouter", j'ai l'erreur suivante:
An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: La colonne 'Numéro PI' n'appartient pas à la table .

Or j'ai bien vérifier, il y'a bien cette colonne dans la base de données... .

Je vous laisse le code de la fenêtre concerner:

**********************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Common;

namespace WindowsFormsApplication2
{
    public partial class Modification : Form
     {  
       
        OleDbConnection ADONetConnection = new OleDbConnection();
        OleDbDataAdapter DataAdapter;
        DataTable Switchs = new DataTable();
        int rowPosition = 0;
   
        public Modification()
        {
            InitializeComponent();
        }

        private void Modification_Load(object sender, EventArgs e)
        {
            // TODO : cette ligne de code charge les données dans la table 'switchscruasDataSet.Switchs'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
            this.switchsTableAdapter.Fill(this.switchscruasDataSet.Switchs);
        }

        private void Supprimer_Click(object sender, EventArgs e)
        {
            // Supression de la ligne courante.
            if (Switchs.Rows.Count != 0)
            {
                Switchs.Rows[rowPosition].Delete();
                DataAdapter.Update(Switchs);
                rowPosition = 0;
                this.ShowCurrentRecord();
            }

        }
               
        private void ShowCurrentRecord()
        {
         
        }

        private void Changement_Click(object sender, EventArgs e)
        {

        }

        private void Ajout_Click(object sender, EventArgs e)
        {
            DataRow drNewRow = Switchs.NewRow();

            drNewRow["Numéro PI"] = "";
            drNewRow["Adresse MAC"] = "";
            drNewRow["Switch"] = "";
            drNewRow["Lieu"] = "";

            Switchs.Rows.Add(drNewRow);
            DataAdapter.Update(Switchs);
            rowPosition = Switchs.Rows.Count +1;
            this.ShowCurrentRecord();

        }

        private void Quitter_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

    }
}
************************************************************************

Merci pour votre aide 

1 réponse

maladebe Messages postés 18 Date d'inscription jeudi 8 mai 2003 Statut Membre Dernière intervention 27 mars 2009
25 févr. 2009 à 11:41
Salut,
Le problème se situe peut-être au niveau des noms de colonnes qui comportent des espaces.
Essaie en remplaçant :
drNewRow["Numéro PI"] = "";
par :
drNewRow["[Numéro PI]"] = "";

Peux-tu nous donner ta requete SQL?
0
Rejoignez-nous