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

VB.NET Discussion :

parcourir et arranger datatable


Sujet :

VB.NET

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    745
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 745
    Par défaut parcourir et arranger datatable
    bonjour, grace a une requete sql assez complexe, j'obtiens une datatable de ce 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
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
     
     Pa	97	    2.0905 %	OVE	8	10
     Pa	97	    2.0905 %	LVE	9	24
     Pa	97	    2.0905 %	GOO	12	22
    CEL	2	    0.0431 %	NEW	1	22
    DIM	4	    0.0862 %	PRO	4	5
    DIM	4	    0.0862 %	KEL	4	12
    DIM	4	    0.0862 %	OVE	8	10
    ESV	1	    0.0215 %	LOC	1	3
    ESV	1	    0.0215 %	 Pa	1	97
    GOO	22	    0.4741 %	YAH	2	4
    GOO	22	    0.4741 %	 Pa	12	97
    KEL	12	    0.2586 %	DIM	4	4
    KEL	12	    0.2586 %	 Pa	7	97
    KEL	12	    0.2586 %	OVE	8	10
    LOC	3	    0.0646 %	LVE	1	24
    LOC	3	    0.0646 %	ESV	1	1
    LOC	3	    0.0646 %	 Pa	2	97
    LVE	24	    0.5172 %	KEL	4	12
    LVE	24	    0.5172 %	OVE	4	10
    LVE	24	    0.5172 %	 Pa	9	97
    MIV	3	    0.0646 %	 Pa	3	97
    NEW	22	    0.4741 %	 Pa	1	97
    NEW	22	    0.4741 %	CEL	1	2
    OVE	10	    0.2155 %	DIM	8	4
    OVE	10	    0.2155 %	 Pa	8	97
    OVE	10	    0.2155 %	PRO	10	5
    PRO	5	    0.1077 %	KEL	4	12
    PRO	5	    0.1077 %	DIM	4	4
    PRO	5	    0.1077 %	OVE	10	10
    YAH	4	    0.0862 %	GOO	2	22
    j'aimerai la parcourir pour la mettre en forme de maniere a ce que j'obtienne une datatable comme cela :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Pa	97	    2.0905 %	OVE	8	10	LVE	9	24	GOO	12	22
    CEL	2	    0.0431 %	NEW	1	22
    DIM	4	    0.0862 %	PRO	4	5	KEL	4	12	OVE	8	10
    ESV	1	    0.0215 %	LOC	1	3	 Pa	1	97
    GOO	22	    0.4741 %	YAH	2	4	 Pa	12	97
    KEL	12	    0.2586 %	DIM	4	4	 Pa	7	97	OVE	8	10

    c'est a dire faire un filtre sur la premiere colonne de maniere a ne me renvoyer que des lignes uniques (pour la premiere), puis ajouter a cette ligne soit trois soit 6 colonnes supplémentaires et les remplir correctement suivant les données....


    Suis je clair???


    D'avance merci!


    PS:
    ma datable est de ce style :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Dim dtRef As New DataTable()
     
            dtRef.Columns.Add(New DataColumn("Ref", GetType(String)))
            dtRef.Columns.Add(New DataColumn("NbRef", GetType(Integer)))
            dtRef.Columns.Add(New DataColumn("Poids", GetType(String)))
     
            dtRef.Columns.Add(New DataColumn("ReferentB", GetType(String)))
            dtRef.Columns.Add(New DataColumn("NbrReferentB", GetType(Integer)))
            dtRef.Columns.Add(New DataColumn("NbrTotalReferentB", GetType(Integer)))

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    745
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 745
    Par défaut
    j'ai bien essayé un truc comme cela :


    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
    For ntmp = 0 To dtRef.Rows.Count - 1
                dtRef.DefaultView.RowFilter = "Ref = " & dtRef.Columns("Ref").ToString
                dtRow = dtOrg.NewRow()
                dtRow("Ref") = dtRef.DefaultView.Item(ntmp)("Ref").ToString
     
                dtRow("NbRef") = dtRef.DefaultView.Item(ntmp)("NbRef")
     
                dtRow("Poids") = dtRef.DefaultView.Item(ntmp)("Poids")
     
                dtRow("ReferentB") = dtRef.DefaultView.Item(ntmp)("ReferentB")
     
                dtRow("NbrReferentB") = dtRef.DefaultView.Item(ntmp)("NbrReferentB")
     
                dtRow("NbrTotalReferentB") = dtRef.DefaultView.Item(ntmp)("NbrTotalReferentB")
     
                dtRow("ReferentC") = dtRef.DefaultView.Item(ntmp)("ReferentB")
     
                dtRow("NbrReferentC") = dtRef.DefaultView.Item(ntmp)("NbrReferentB")
     
                dtRow("NbrTotalReferentC") = dtRef.DefaultView.Item(ntmp)("NbrTotalReferentB")
     
                dtRow("ReferentD") = dtRef.DefaultView.Item(ntmp)("ReferentB")
     
                dtRow("NbrReferentD") = dtRef.DefaultView.Item(ntmp)("NbrReferentB")
     
                dtRow("NbrTotalReferentD") = dtRef.DefaultView.Item(ntmp)("NbrTotalReferentB")
     
                dtOrg.Rows.Add(dtRow)
            Next

    malheureusement le rendu n'est pas ca du tout! :

    Ref NbRef Poids ReferentB NbrReferentB NbrTotalReferentB ReferentC NbrReferentC NbrTotalReferentC ReferentD NbrReferentD NbrTotalReferentD
    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
    Pa 97 2.0905 % OVE 8 10 OVE 8 10 OVE 8 10 
    Pa 97 2.0905 % LVE 9 24 LVE 9 24 LVE 9 24 
    Pa 97 2.0905 % GOO 12 22 GOO 12 22 GOO 12 22 
    CEL 2 0.0431 % NEW 1 22 NEW 1 22 NEW 1 22 
    DIM 4 0.0862 % PRO 4 5 PRO 4 5 PRO 4 5 
    DIM 4 0.0862 % KEL 4 12 KEL 4 12 KEL 4 12 
    DIM 4 0.0862 % OVE 8 10 OVE 8 10 OVE 8 10 
    ESV 1 0.0215 % LOC 1 3 LOC 1 3 LOC 1 3 
    ESV 1 0.0215 % Pa 1 97 Pa 1 97 Pa 1 97 
    GOO 22 0.4741 % YAH 2 4 YAH 2 4 YAH 2 4 
    GOO 22 0.4741 % Pa 12 97 Pa 12 97 Pa 12 97 
    KEL 12 0.2586 % DIM 4 4 DIM 4 4 DIM 4 4 
    KEL 12 0.2586 % Pa 7 97 Pa 7 97 Pa 7 97 
    KEL 12 0.2586 % OVE 8 10 OVE 8 10 OVE 8 10 
    LOC 3 0.0646 % LVE 1 24 LVE 1 24 LVE 1 24 
    LOC 3 0.0646 % ESV 1 1 ESV 1 1 ESV 1 1 
    LOC 3 0.0646 % Pa 2 97 Pa 2 97 Pa 2 97 
    LVE 24 0.5172 % KEL 4 12 KEL 4 12 KEL 4 12 
    LVE 24 0.5172 % OVE 4 10 OVE 4 10 OVE 4 10 
    LVE 24 0.5172 % Pa 9 97 Pa 9 97 Pa 9 97 
    MIV 3 0.0646 % Pa 3 97 Pa 3 97 Pa 3 97 
    NEW 22 0.4741 % Pa 1 97 Pa 1 97 Pa 1 97 
    NEW 22 0.4741 % CEL 1 2 CEL 1 2 CEL 1 2 
    OVE 10 0.2155 % DIM 8 4 DIM 8 4 DIM 8 4 
    OVE 10 0.2155 % Pa 8 97 Pa 8 97 Pa 8 97 
    OVE 10 0.2155 % PRO 10 5 PRO 10 5 PRO 10 5 
    PRO 5 0.1077 % KEL 4 12 KEL 4 12 KEL 4 12 
    PRO 5 0.1077 % DIM 4 4 DIM 4 4 DIM 4 4 
    PRO 5 0.1077 % OVE 10 10 OVE 10 10 OVE 10 10 
    YAH 4 0.0862 % GOO 2 22 GOO 2 22 GOO 2 22
    je suis un peu a cours d'idée la....

  3. #3
    Membre expérimenté
    Inscrit en
    Novembre 2006
    Messages
    337
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 337
    Par défaut
    Euh juste comme ca tu as du faire un copier coller car il y a plusieur fois
    nbreferenceB, et des truc comme ca ... t'est sur que ton code est correcte ??

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    745
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 745
    Par défaut
    bah justement j'ai testé et le resultat n'est pas convaincant donc non le code n'est pas correct....

  5. #5
    Membre expérimenté
    Inscrit en
    Novembre 2006
    Messages
    337
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 337
    Par défaut
    Il faut modifier ta datatable, elle doit etre du type :
    SI c'est possible evidemment...

    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
     
    dtRef.Columns.Add(New DataColumn("Ref", GetType(String)))
            dtRef.Columns.Add(New DataColumn("NbRef", GetType(Integer)))
            dtRef.Columns.Add(New DataColumn("Poids", GetType(String)))
     
            dtRef.Columns.Add(New DataColumn("ReferentB", GetType(String)))
            dtRef.Columns.Add(New DataColumn("NbrReferentB", GetType(Integer)))
            dtRef.Columns.Add(New DataColumn("NbrTotalReferentB", GetType(Integer)))
     
    dtRef.Columns.Add(New DataColumn("ReferentD", GetType(String)))
            dtRef.Columns.Add(New DataColumn("NbrReferentC", GetType(Integer)))
            dtRef.Columns.Add(New DataColumn("NbrTotalReferentC", GetType(String)))
     
            dtRef.Columns.Add(New DataColumn("ReferentD", GetType(String)))
            dtRef.Columns.Add(New DataColumn("NbrReferentD", GetType(Integer)))
            dtRef.Columns.Add(New DataColumn("NbrTotalReferentD", GetType(Integer)))

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    745
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 745
    Par défaut
    ce que j'ai fait c'est une autre datatable :


    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
    Dim dtOrg as New datatable()
     dtOrg.Columns.Add(New DataColumn("Ref", GetType(String)))
            dtOrg.Columns.Add(New DataColumn("NbRef", GetType(Integer)))
            dtOrg.Columns.Add(New DataColumn("Poids", GetType(String)))
     
            dtOrg.Columns.Add(New DataColumn("ReferentB", GetType(String)))
            dtOrg.Columns.Add(New DataColumn("NbrReferentB", GetType(Integer)))
            dtOrg.Columns.Add(New DataColumn("NbrTotalReferentB", GetType(Integer)))
     
            dtOrg.Columns.Add(New DataColumn("ReferentC", GetType(String)))
            dtOrg.Columns.Add(New DataColumn("NbrReferentC", GetType(Integer)))
            dtOrg.Columns.Add(New DataColumn("NbrTotalReferentC", GetType(Integer)))
     
            dtOrg.Columns.Add(New DataColumn("ReferentD", GetType(String)))
            dtOrg.Columns.Add(New DataColumn("NbrReferentD", GetType(Integer)))
            dtOrg.Columns.Add(New DataColumn("NbrTotalReferentD", GetType(Integer)))

    mais ca ne resout pas mon pb....

  7. #7
    Membre expérimenté
    Inscrit en
    Novembre 2006
    Messages
    337
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 337
    Par défaut
    Perso je trouve que l'on s'embrouille un peu trop pour rien, avec une requete SQL bien montée y'a moyen d'eviter tout ce bor##l. Sinon, comment fait tu pour la recuperation de tes données. Peut tu mettre le code de recuperation des données et d'insertion dans la datatable STP

  8. #8
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    745
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 745
    Par défaut
    si tu veux voir les requetes y a aussi un post dans le Langage sql!

    mais les requetes sont deja bien assez complexe comme cela!!

    Enfin bref excuse moi mais j'avoue que la j'en ai un peu marre de tourner en rond et de n'arriver a rien!


    merci qd mm d'essayer de m'aider!

  9. #9
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    127
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Mars 2007
    Messages : 127
    Par défaut
    Moi je verrais un truc dans le genre
    Compter le nombre maximale d'une occurence
    définir un datatable avec le nombre de colonne maximale possible
    pour chaque groupe d'occurence, tu ajoute une row avec
    3 colonnes pour les résultats similaires, puis après tu ajoutes a la suite les non similaires
    J'espère que ça pourra t'aider

Discussions similaires

  1. Parcourir une datatable
    Par élève_ingénieur dans le forum JSF
    Réponses: 2
    Dernier message: 19/07/2011, 11h14
  2. Parcourir une datatable par groupe
    Par olibara dans le forum Linq
    Réponses: 2
    Dernier message: 16/06/2010, 21h33
  3. arrangement des colonnes dans datatable
    Par pbatty1 dans le forum C#
    Réponses: 7
    Dernier message: 12/04/2010, 15h03
  4. parcourir un datatable
    Par marclas dans le forum VB.NET
    Réponses: 2
    Dernier message: 14/12/2009, 11h45
  5. Parcourir une datatable et generer un textbox
    Par pascal_70 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 26/02/2008, 16h30

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