C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Hot to import data set to a CSV file


Posted Date: 19 Nov 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: MASNSNMember Level: Gold    
Rating: 1 out of 5Points: 10



After filling a data set using a data adapter you can export all the data tables to a given CSV file using this code snipet, Of Corse, I suppose in this code that my data set is named ds, you can repace it by your data set name

List oList = new List();
foreach (DataTable t in ds.Tables)
{

oList.Add(t.TableName);
oList.Add(Environment.NewLine);
foreach (DataRow r in dt.Rows)
{
foreach (DataColumn c in dt.Columns)
{
oList.Add(c.Caption + " " + r[c].ToString() + " ");

}
}
oList.Add(Environment.NewLine);
oList.Add(Environment.NewLine);
}

System.IO.File.WriteAllLines(@"C:\myFile.csv", oList.ToArray());
oConn.Close();
MessageBox.Show("Done");




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Export import data set data table access sql server CSV file C#  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: convert a string to an int
Previous Resource: Indexer in C#
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use