Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Lecture des fichier CSV

Recherche,dans,la,base,de,données:,non,édité
{filelink=16154}

//This example code is from eran.rivlis at gmail.com
 
   DataTable dt = new DataTable();
 
       private void Form1_Load(object sender, EventArgs e)
       {
           string conString =  @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:csv" +
                  @";Extended Properties=""Text;HDR=No;FMT=Delimited""";
           OleDbConnection conn = new OleDbConnection(conString);
           OleDbDataAdapter da = new OleDbDataAdapter(@"Select * from table1.csv", conn);
           da.Fill(dt);
           dataGridView1.DataSource = dt;
       }
 
       private void button1_Click(object sender, EventArgs e)
       {
           StringBuilder sbCSV = new StringBuilder();
           int intColCount = dt.Columns.Count;
           foreach (DataRowView dr in dt.DefaultView)
           {
                   for (int x = 0; x < intColCount; x++)
                   {
                       sbCSV.Append(dr[x].ToString());
                       if ((x + 1) != intColCount)
                       {
                           sbCSV.Append(",");
                       }
                   }
                   sbCSV.Append("
");
           }
           using (StreamWriter sw = new StreamWriter(@"c:csv	able1.csv"))
           {
               sw.Write(sbCSV.ToString());
           }
       }

No comments yet.

Leave a Comment