how can i save different data to text file separated by commas and the text file shoul handle 5 records

What code have you got so far for this?

What is the data etc?


Does it mean to Export your Data from Datatable to Word Document?If so,I can provide you the following codes to achieve this.

**Step1. Function to fill data in datatable **

private void Form1_Load(object sender, EventArgs e)
            oleDbConnection1.ConnectionString = txtConnectString.Text;
            oleDbCommand1.CommandText = txtCommandText.Text;
            using (OleDbDataAdapter da = new OleDbDataAdapter())
                da.SelectCommand = oleDbCommand1;
                da.SelectCommand.Connection = oleDbConnection1;
                DataTable dt = new DataTable();
                dataGridView1.DataSource = dt;

Step2. Export Data to word document

private void btnExportToWord_Click(object sender, EventArgs e)
            Spire.DataExport.RTF.RTFExport rtfExport = new Spire.DataExport.RTF.RTFExport();
            rtfExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            rtfExport.DataTable = this.dataGridView1.DataSource as DataTable;
            rtfExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            RTFStyle rtfStyle = new RTFStyle();
            rtfStyle.FontColor = Color.Blue;
            rtfStyle.BackgroundColor = Color.LightGreen;
            rtfExport.RTFOptions.DataStyle = rtfStyle;

Alternatively,if you dont mind using a 3rd party data library,you can check this.Hope it helps.

from DataBase-> to textfile?
1.Create a File (ex: *.txt)
2.Fill DataTable object from Database using select command
3.using foreach the each row from that dataTableObject's data will append to a single string
4.append the string with already created *.txt file

DataTable dt=new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select * from tbl2", con);
DataGridView1.DataSource = dt;
foreach DataRow drow In dt.Rows
  String str= drow("column1") + " " + drow("column2") + " " + drow("column3") + " ";
 }"Data Exported Successfully");