title: Export to csv to ignore commas and line breaks in comments
body: <p>I have the below code that exports to csv fine, but just realised it doesn't handle commas or line breaks in the 'comments' field textbox. Is there a way to ignore commas and line breaks in a particular field or in all of them?</p>
  
  <pre><code>private void saveFileDialogTrack_FileOk(object sender, CancelEventArgs e)
      {
          StringBuilder str = new StringBuilder();
          foreach (DataRow dr in this.trackDataSet.Track)
          {
              foreach (object field in dr.ItemArray)
              {
                  str.Append(field.ToString() + ",");
              }
              str.Replace(",", Environment.NewLine, str.Length - 1, 1);
          }
          string name = saveFileDialogTrack.FileName;
          try
          {
              System.IO.File.WriteAllText(name, str.ToString());
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.ToString());
          }
          str = null;
      }
  </code></pre>
  
  <p>Sample csv (first few fields) Barbagallo,31,39,51.01,</p>
  
  <pre><code>        private void openFileDialogTrack_FileOk(object sender, CancelEventArgs e)
      {
          try
          {
              using (StreamReader SR = new StreamReader(openFileDialogTrack.FileName))
              {
                  while (!SR.EndOfStream)
                  {
                      var CSValues = SR.ReadLine().Split(',');
  
                      SqlCeConnection myConnection = new SqlCeConnection("Data Source = Track.sdf");
                      myConnection.Open();
                      String str = (@"INSERT INTO Track (Track, StartFinishLineNSDegrees, StartFinishLineNSMinutes, 
  </code></pre>
  
  <p>......................</p>
  
  <pre><code>VALUES (@track, @SFNSD, @SFNSM,
  </code></pre>
  
  <p>......................</p>
  
  <pre><code>                        SqlCeCommand cmd = new SqlCeCommand(str, myConnection);
                      cmd.Parameters.AddWithValue("@track", CSValues[0] == string.Empty ? (object)DBNull.Value : CSValues[0]);
                      cmd.Parameters.AddWithValue("@SFNSD", CSValues[1] == string.Empty ? (object)DBNull.Value : CSValues[1]);
                      cmd.Parameters.AddWithValue("@SFNSM", CSValues[2] == string.Empty ? (object)DBNull.Value : CSValues[2]);
  </code></pre>