Export dataset to a comma delimited text file


This article helps us about how to Export dataset to a comma delimited text file

This code reads the dataset and exports data(eg: customers table) to a text file. Column values are delimited by comma.



string[] rowString = new string[dataSet11.Tables["Customers"].Rows.Count];
int i=0;
foreach (DataRow dr in dataSet11.Tables["Customers"].Rows)
{
rowString[i] = dr.ItemArray.GetValue(0).ToString() + ",";
rowString[i] += dr.ItemArray.GetValue(1).ToString() + ",";
rowString[i] += dr.ItemArray.GetValue(2).ToString();
i++;
}
File.WriteAllLines(@"C:\customer.txt", rowString);
MessageBox.Show("Data Exported to text file");




Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: