C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Exporting Data to CSV Posted by luihond on 21 Nov 2007 at 5:20 AM
Hi Guys. I am trying to export data from my Access DB to a CSV file. I have managed to get this work OK, however, I want to take this one step further in that I want to only export data in the DB that have a value of '0' in the "EXPORTED" Column. I have done the below in the export code but it gives me an error.

            //Write all records in the DB
            foreach (DataRow dr in dt.Rows) 
            {
                if (dr["Exported"] == '0')
                {
                    for (int i = 0; i < iColCount; i++)
                    {
                        if (!Convert.IsDBNull(dr[i]))
                        {
                            sw.Write(dr[i].ToString());
                        }
                        if (i < iColCount - 1)
                        {
                            sw.Write(",");
                        }
                    }
                }
            
                sw.Write(sw.NewLine);
            

            }

            sw.Close();


The error I get is as follows:
"Operator '==' cannot be applied to the operands of type 'string' and 'char'

Does anybody know how I can get past this?
Report
Re: Exporting Data to CSV Posted by zibadian on 21 Nov 2007 at 6:37 AM
: Hi Guys. I am trying to export data from my Access DB to a CSV
: file. I have managed to get this work OK, however, I want to take
: this one step further in that I want to only export data in the DB
: that have a value of '0' in the "EXPORTED" Column. I have done the
: below in the export code but it gives me an error.
:
:
: 
:             //Write all records in the DB
:             foreach (DataRow dr in dt.Rows) 
:             {
:                 if (dr["Exported"] == '0')
:                 {
:                     for (int i = 0; i < iColCount; i++)
:                     {
:                         if (!Convert.IsDBNull(dr[i]))
:                         {
:                             sw.Write(dr[i].ToString());
:                         }
:                         if (i < iColCount - 1)
:                         {
:                             sw.Write(",");
:                         }
:                     }
:                 }
:             
:                 sw.Write(sw.NewLine);
:             
: 
:             }
: 
:             sw.Close();
: 
:
:
: The error I get is as follows:
: "Operator '==' cannot be applied to the operands of type 'string'
: and 'char'
:
: Does anybody know how I can get past this?
:
There are 3 ways:
- Change the field-type into a char
- Dynamically get the first char of the string
- Change '0' into a string



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.