This example will read a csv file into a dataset and save it back when you press button 1 : CSV « Database ADO.net « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Database ADO.net » CSVScreenshots 
This example will read a csv file into a dataset and save it back when you press button 1



//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("\n");
           }
           using (StreamWriter sw = new StreamWriter(@"c:\csv\table1.csv"))
           {
               sw.Write(sbCSV.ToString());
           }
       
           
           
       
Related examples in the same category
1. Read comma separated value into DataSetRead comma separated value into DataSet
w__w__w_.ja__v__a___2_s___.__c_o_m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.