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

C# Discussion :

problemes d'insertion des champs dans un fichier txt


Sujet :

C#

  1. #1
    Futur Membre du Club
    Inscrit en
    Mai 2010
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 5
    Points : 5
    Points
    5
    Par défaut problemes d'insertion des champs dans un fichier txt
    Je suis débutant en c#, j'ai un data table qui contient deux colonne timemodif et filename
    Comment je récupères les lignes dans un fichier texte
    voici mon code que j'ai utilisé
    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
     
    StreamWriter sw = new StreamWriter("C:\\Documents and Settings\\Jihed\\Desktop\\code.txt", false);
    foreach (DataRow row in table.Rows)
     
                {
     
                    object[] array = row.ItemArray;
     
                    for (int i = 0; i < array.Length - 1; i++)
                    {
                        sw.Write(array[i].ToString() + " ");
     
     
                    }
     
                    int j = 0;
                    sw.Write(array[j].ToString());
                    sw.WriteLine();
                }
    voici le resultat ecrites sur mon fichier texte
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    C:\eula.1042.txt C:\eula.1042.txt
    C:\eula.1041.txt C:\eula.1041.txt
    C:\eula.3082.txt C:\eula.3082.txt
    C:\eula.2052.txt C:\eula.2052.txt
    C:\eula.1040.txt C:\eula.1040.txt
    C:\eula.1031.txt C:\eula.1031.txt
    C:\eula.1028.txt C:\eula.1028.txt
    C:\eula.1036.txt C:\eula.1036.txt
    C:\eula.1033.txt C:\eula.1033.txt
    cependant en les affichant dans un datagridview je vois les deus colonne qui contienne les deux champs

  2. #2
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut Impression du nom de classe au lieu du contenu
    bonjour
    tu as imprime le nom de classe de l'array object au lieu du contenu de l'array.
    code:
    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
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
     
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                String chemin =Directory.GetCurrentDirectory() ;
                StreamWriter sw = new StreamWriter(chemin + "\\code.txt", false);
     
                 foreach (DataRow row in table.Rows)
                    {
     
                        object[] array = row.ItemArray;
     
                        for (int i = 0; i < array.Length ; i++)
                        {
                            //manquant toString
                            sw.Write(array[i].ToString() + " ");
                        }
     
                        int j = 0;
                        //manquant toString
                        sw.Write(array[j].ToString());
                        sw.WriteLine();
                    }
                //manquant
                    sw.Close();
     
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                this.wilayaTableAdapter1.Fill(this.bdWilayaDataSet1.WILAYA);
     
            }
        }
    }
    bon code....

Discussions similaires

  1. insertion des données dans un fichier xml
    Par totomimi dans le forum Format d'échange (XML, JSON...)
    Réponses: 0
    Dernier message: 29/06/2009, 00h48
  2. probleme d'insertion des données dans un datagridview
    Par meryDev dans le forum Windows Forms
    Réponses: 0
    Dernier message: 20/06/2009, 14h14
  3. Réponses: 2
    Dernier message: 18/06/2009, 15h26
  4. Lire des champs dans une fichier texte
    Par darkman13130 dans le forum C++Builder
    Réponses: 17
    Dernier message: 06/06/2008, 16h31
  5. Insertion de champs dans un fichier
    Par flouflou dans le forum Linux
    Réponses: 3
    Dernier message: 16/08/2004, 14h48

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