Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 22nd, 2006, 11:25 AM
Registered User
Join Date: May 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help in exporting memo fields to CSV file

Hi Everyone:

I was trying to export a memo field from an Access file to CSV (comma separated value) file using C#. But the code is not producing the desired result because the memo field is getting broken into several cells.

The field "Description" is a memo field. I have the memo field in a temporary file called "ds". I am not able to send this field to the CSV file.

I'll explain a little bit about what i am doing in the "for" loop. I was trying to convert all the fields to string and keep each of the field in quotes so that if any filed has a comma within it that field won't get divided into two different field when the file is opened in excel.

I'd really appreciate if anyone could suggest a solution.

Thanks in Advance.


        private void bt_export2excel_Click(object sender, EventArgs e)
            String PerfData = "";
            String filename = "";

                using (SqlCommand HFcomm = new SqlCommand(" SELECT F20, F1, F2,F3,F4,F5,F6,F7, F9, F10,F11, Description FROM Information INNER JOIN SPVendor ON Information.DataVendorName=SPVendor.DataVendorName and Information.DataVendorID=SPVendor.DataVendorID WHERE SPVendor.GID= " + this.gid, this.HFconn))
                    SqlDataAdapter adapt = new SqlDataAdapter();
                    DataSet ds = new DataSet();
                    adapt.SelectCommand = HFcomm;

                    using (SaveFileDialog savefile = new SaveFileDialog())
                        savefile.Filter = "CSV files (*.csv)|*.csv";
                        savefile.RestoreDirectory = true;
                        savefile.Title = "Save the Return";
                        filename = savefile.FileName;
                    TextWriter tw = new StreamWriter(filename);

                    if (filename != "")
                        PerfData = "Name" + "," + "Manager" + "," + "Address" + "," + "Address" + "," + "City" + "," + "State" + "," + "ZIP" + "," + "Country" + "," + "Tel" + "," + "Fax" + "," + "E-mail" + ",";

                        foreach (DataRow rw in ds.Tables[0].Rows)
                            PerfData = "";
                            for (int i = 0; i < rw.Table.Columns.Count; i++)

                                PerfData += "\"" + rw[i].ToString() + "\"" + ",";


            catch (System.ArgumentNullException)
                MessageBox.Show("Provide a valid file name");

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting a csv file (comma separated) micharl Beginning VB 6 6 May 7th, 2008 10:10 PM
Exporting a Datagrid to a CSV file pauljohns353 Visual Basic 2005 Basics 1 November 21st, 2006 04:56 PM
Exporting Data from DataGrid to a CSV file PT ASP.NET 1.0 and 1.1 Professional 2 June 22nd, 2005 04:41 AM
Memo Fields with Windows Forms in C# jim.stanley Access 0 November 15th, 2004 05:55 PM
Memo fields takabyte Classic ASP Basics 2 October 31st, 2003 06:13 PM

All times are GMT -4. The time now is 12:45 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.