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");