title: How to get Header text as required in CSV file in Windows Application?
body: <p>I am using the following code to generate CSV file:</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
      {
  
          Stopwatch swra = new Stopwatch();
          swra.Start();
          string NewconnectionString = connectionString;
          StreamWriter CsvfileWriter = new StreamWriter(@"D:\testfile.csv");
          string sqlselectQuery = "select * from tblProperty";
          SqlCommand sqlcmd = new SqlCommand();
  
          SqlConnection spContentConn = new SqlConnection(NewconnectionString);
          sqlcmd.Connection = spContentConn;
          sqlcmd.CommandTimeout = 0;
          sqlcmd.CommandType = CommandType.Text;
          sqlcmd.CommandText = sqlselectQuery;
          spContentConn.Open();
          using (spContentConn)
          {
              using (SqlDataReader sdr = sqlcmd.ExecuteReader())
              using (CsvfileWriter)
              {
                  string columnNames = Enumerable.Range(0, sdr.FieldCount).Select(i =&gt; sdr.GetName(i)).ToString();
  
  
                  CsvfileWriter.WriteLine(string.Join(",", columnNames));
                  while (sdr.Read())
                      //based on your Table columns you can increase and decrese columns
                      CsvfileWriter.WriteLine(sdr[0].ToString() + "," + sdr[1].ToString() + "," + sdr[2].ToString() + "," + sdr[3].ToString() + "," + sdr[4].ToString() + "," + sdr[5].ToString() + "," + sdr[6].ToString() + "," + sdr[7].ToString() + "," + sdr[8].ToString() + "," + sdr[9].ToString() + ",");
  
              }
          }
          swra.Stop();
          Console.WriteLine(swra.ElapsedMilliseconds);
      }
  </code></pre>
  
  <p>And in out put i get the data as below screen shot 
  <img src="https://i.stack.imgur.com/4FZjB.png" alt="this">
  please help me.
  Thanks in advance.</p>