IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

Erreur databinding data grid


Sujet :

ASP.NET

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    391
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 391
    Par défaut Erreur databinding data grid
    Bonjour

    J'ai une datagrid declaré dans une page aspx

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     <asp:DataGrid ID="DataGrid1" HorizontalAlign="Center" CellPadding="3"
        HeaderStyle-BackColor="#F7F7F7" EditItemStyle-BackColor="#F7F7F7"
        AutoGenerateColumns="false" DataKeyField="IdNum"  
        Runat="server" BorderColor="#207DBC" BorderWidth="3px" CellSpacing="3" 
                    CssClass="body_txt" BorderStyle="Solid">
     
        <EditItemStyle BackColor="#F7F7F7"></EditItemStyle>
     
               <Columns>            
               <asp:BoundColumn DataField="DateEvent" HeaderText="DATE"/>   
               <asp:BoundColumn DataField="IdTag" HeaderText="TAG UID"/>   
               <asp:BoundColumn DataField="Nom" HeaderText="MANUFACTURER"/>       
               <asp:BoundColumn DataField="Description" HeaderText="DESCRIPTION"/> 
               <asp:BoundColumn DataField="Diametre" HeaderText="DIAMETER"/>  
               <asp:BoundColumn DataField="Longueur" HeaderText="LENGTH"/>          
               <asp:BoundColumn DataField="State" HeaderText="ACTION"/>        
     
               </Columns>
    Ce datagrid se remplit par un requete SQL qui est testée directement et semble marcher correctement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     private void BindDataGrid(int user)
        {
            MySqlConnection Connection = new MySqlConnection();
            Connection.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString;
            try
            {
                // Ici, on ouvre la connexion au serveur
                Connection.Open();
            }
            catch (Exception excp)
            {
                Exception myExcp = new Exception("Could not Open. Error: " +
                    excp.Message, excp);
                throw (myExcp);
            }
    
           // string MySQLCmd = string.Format("SELECT e.DateEvent,a.IdTag,b.State,d.Nom,d.Description,d.Diametre,d.Longueur,b.IdNum,c.RefProduit,d.Reference,e.IdNum,e.IdUser FROM tageventtable a,statetable b,produittable c,producttable d,readereventtable e WHERE a.IdState<>2 AND a.IdState=b.IdNum AND a.IdEvent=e.IdNum AND a.IdTag=c.TagId AND e.IdUser={0} AND c.RefProduit=d.Reference ORDER BY e.DateEvent DESC LIMIT 20", user);
            string MySQLCmd = string.Format("SELECT b.DateEvent,a.IdTag,d.Nom,d.Description,d.Diametre,d.Longueur,e.State FROM tageventtable a JOIN readereventtable b ON a.IdEvent=b.IdNum JOIN produittable c ON a.IdTag=c.TagId JOIN producttable d ON d.Reference=c.RefProduit JOIN statetable e ON e.IdNum=a.IdState WHERE b.IdUser={0} AND a.IdState<>2 ORDER BY b.DateEvent DESC LIMIT 20;", user);
            MySqlCommand readEvent = new MySqlCommand(MySQLCmd, Connection);
    
            try
            {
                DataGrid1.DataSource = readEvent.ExecuteReader();
                DataGrid1.DataBind();
                readEvent.Dispose();
            }
            catch (Exception ex)
            {
                Response.Write("An error occured: " + ex.Message);
            }
            Connection.Close();
        }
    Par contre en pas a pas j'ai l'erreur suivante

    An error occured: DataBinding : 'System.Data.Common.DataRecordInternal' ne comporte pas de propriété appelée 'IdNum'.
    qui arrive au niveau du la ligne rouge et je ne comprend le sens de cette erreur car je ne select pas la colonne Idnum mais elle me sert pour trier mes colonnes dans les predicat des JOIN


    Si Qq'un peut m'aiguiller

    cordialement

  2. #2
    Membre Expert Avatar de Arthis
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 265
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : Italie

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 265
    Par défaut
    si tu ne la selectionne aps dans ta requete comment est ce que ton grifview pourrait l'utiliser ensuite?

    ...tu sais ce qu'il te reste à faire...

    petit conseil en passant , évites ceci, cela ne t'avance à rien :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
      try
            {
                // Ici, on ouvre la connexion au serveur
                Connection.Open();
            }
            catch (Exception excp)
            {
                Exception myExcp = new Exception("Could not Open. Error: " +
                    excp.Message, excp);
                throw (myExcp);
            }
    contente toi de cela:


  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    391
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 391
    Par défaut
    Bonjour

    Merci pour ta reponse mais je ne l'a comprend pas.
    si tu ne la selectionne aps dans ta requete comment est ce que ton grifview pourrait l'utiliser ensuite?

    ...tu sais ce qu'il te reste à faire...
    Ce n'est pas ce que je fait avec le deuxieme du try catch
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    // string MySQLCmd = string.Format("SELECT e.DateEvent,a.IdTag,b.State,d.Nom,d.Description,d.Diametre,d.Longueur,b.IdNum,c.RefProduit,d.Reference,e.IdNum,e.IdUser FROM tageventtable a,statetable b,produittable c,producttable d,readereventtable e WHERE a.IdState<>2 AND a.IdState=b.IdNum AND a.IdEvent=e.IdNum AND a.IdTag=c.TagId AND e.IdUser={0} AND c.RefProduit=d.Reference ORDER BY e.DateEvent DESC LIMIT 20", user);
            string MySQLCmd = string.Format("SELECT b.DateEvent,a.IdTag,d.Nom,d.Description,d.Diametre,d.Longueur,e.State FROM tageventtable a JOIN readereventtable b ON a.IdEvent=b.IdNum JOIN produittable c ON a.IdTag=c.TagId JOIN producttable d ON d.Reference=c.RefProduit JOIN statetable e ON e.IdNum=a.IdState WHERE b.IdUser={0} AND a.IdState<>2 ORDER BY b.DateEvent DESC LIMIT 20;", user);
            MySqlCommand readEvent = new MySqlCommand(MySQLCmd, Connection);
     
            try
            {
                DataGrid1.DataSource = readEvent.ExecuteReader();
                DataGrid1.DataBind();
                readEvent.Dispose();
            }
            catch (Exception ex)
            {
                Response.Write("An error occured: " + ex.Message);
            }
            Connection.Close();
    Si ce n'est pas cela peut tu m'en dire un peu plus

    Cordialement

  4. #4
    Expert confirmé
    Avatar de Immobilis
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2004
    Messages
    6 559
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 559
    Par défaut
    Salut,

    Je penses que tu devrais fortement t'interesser au sujet du découplage des classes.

    Il NE faut PLUS faire d'accès à une base de données dans une interface homme machine. Celle ci est destinée à faire de la mise en page.


    Tu devrais lire ceci: http://dotnet.developpez.com/cours/?...harp#sqlservcs

    Ceci dit un truc du style
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    protected void Page_Load(object sender, EventArgs e)
    {
        GridView g = new GridView();
        using (SqlConnection cn = new SqlConnection())
        {
            cn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            cn.Open();
            using (SqlCommand cm = new SqlCommand("SELECT * FROM COUNTRY;", cn))
            {
                g.DataSource = cm.ExecuteReader();
                g.DataBind();
            }
        }
        PlaceHolder1.Controls.Add(g);
    }
    Fonctionne bien chez moi.

    A+

    A+
    "Winter is coming" (ma nouvelle page d'accueil)

  5. #5
    Membre Expert Avatar de Arthis
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 265
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : Italie

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 265
    Par défaut
    je parlais de ca :

    ta gridview l'u tilise a ce moment la..

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. erreur ASP avec data grid
    Par ledawa dans le forum ASP.NET
    Réponses: 0
    Dernier message: 03/12/2009, 17h50
  2. [Pocket PC] Data grid Personnaliser
    Par Jessika dans le forum Windows Mobile
    Réponses: 4
    Dernier message: 17/11/2006, 09h46
  3. [VB.NET]Probleme Data Grid
    Par ba10 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 24/09/2006, 00h21
  4. Data Grid en Java
    Par m.jaite dans le forum JDBC
    Réponses: 2
    Dernier message: 14/09/2006, 16h13
  5. Data Grid
    Par torNAdE dans le forum MFC
    Réponses: 2
    Dernier message: 02/05/2006, 10h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo