Exporting Data to CSV - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Exporting Data to CSV

luihondluihond Posts: 21Member
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.

[code]
//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();
[/code]

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?

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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.
    :
    : [code]:
    : //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();
    : [/code]:
    :
    : 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
Sign In or Register to comment.