Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4074416
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:09:59+00:00 2026-05-20T17:09:59+00:00

I export the datagridview records in csv file using code : using (StreamWriter myFile

  • 0

I export the datagridview records in csv file using code :

using (StreamWriter myFile = new StreamWriter(filename, false, Encoding.Default))
{
        string sHeaders = "";
        for (int j = 0; j < dGV.Columns.Count; j++)
        {
             if (dGV.Columns[j].Visible)
             {
                 sHeaders = sHeaders.ToString() + dGV.Columns[j].HeaderText + ", "; 
             }
        }
        myFile.WriteLine(sHeaders);
        // Export data.  
        for (int i = 0; i < dGV.RowCount; i++)
        {
             string stLine = "";
             for (int j = 0; j < dGV.Rows[i].Cells.Count; j++)
             {
                 if (dGV.Columns[j].Visible)
                 {
                     stLine = stLine.ToString() + dGV.Rows[i].Cells[j].Value.ToString() + ", ";
                 }
             }
                        myFile.WriteLine(stLine);
        }
     }
  }

But problem is if the value in the datagridviewcell is Harikrishna,Daxini then it will not exported properly,because there is comma in the cell value, but I have a need of including comma in the value.And it should export properly.How can I do that ? I tried with enclosing that value by double quotes and single quotes but it does not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:10:00+00:00Added an answer on May 20, 2026 at 5:10 pm

    Spaces between seperating commas and an opening double quote can cause issues with CSV. Replace code like "val1", "val2" in your csv file with "val1","val2". That should fix your issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to export pictures in Microsoft Word to TIFF file using Visual Studio Tools
I need to export a report to Excel file using PHP i.e. on the
I export an oracle schema using exp userid=/ file=pt.dmp log=pt.log owner=FOO buffer=10000000 statistics=NONE direct=Y
I export try.jar file using 32 bit java libraries. On the client site, I
I'm using the default settings in Eclipse to export my application and have Proguard
I'm trying to export a Crystal Report to a text file, while preserving any
I'm trying to export a Crystal Report to an HTML file, but when I
Can I export multiple calendar events into a single iCalendar file?
How can I export a GridView's data to a Microsoft Excel 2007 file? Also,
export PATH=${/home/mohit/}:<android-sdk-linux_86>/tools this is what i am using.. error:-- bash: PATH=${/home/mohit/}:: bad substitution this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.