views:

43

answers:

1

I have that code:

string pathToSave = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string file = pathToSave + "\\" + "produkty_" + lang + ".csv";
            FileStream fs = new FileStream(file, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
           // sw.WriteLine("id;Akt. 1/0;nazwa;kateg.;cena netto;stawka pod;cen suger.;wyprz.;o;d;d;nr kat.;dostępne od:;prod.;ilość;opis skróc;opis;konserwacja");

            OdbcCommand Qry = new OdbcCommand(query, con);
            OdbcDataReader dataReader = Qry.ExecuteReader();

            while (dataReader.Read())
            {
                //SELECT p.COUNTER, p.AKT, p.NAZWA, p.KATEGORIA, p.CENA_NETTO, p.STAWKA_VAT, 
                //p.CENA_SUGEROWANA, p.WYPRZ, p.O, p.COSTAM, p.D1, p.D2, p.NR_KAT, 
                //p.DOSTEPNE_OD, p.COSTAM2, p.PROD, p.COSTAM3, p.COSTAM4, p.COSTAM5, p.ILOSC, p.OPIS_SKRO, p.COMPOS, p.CONSERV

                string counter         = String.Empty;
                string AKT             = String.Empty;
                string NAZWA           = String.Empty;
                string KATEGORIA       = String.Empty;
                string CENA_NETTO      = String.Empty;
                string STAWKA_VAT      = String.Empty;
                string CENA_SUGEROWANA = String.Empty;
                string WYPRZ           = String.Empty;
                string COSTAM          = String.Empty;
                string D1              = String.Empty;
                string D2              = String.Empty;
                string NR_KAT          = String.Empty;
                string DOSTEPNE_OD     = String.Empty;
                string COSTAM2         = String.Empty;
                string PROD            = String.Empty;
                string COSTAM3         = String.Empty;
                string COSTAM4         = String.Empty;
                string COSTAM5         = String.Empty;
                string ILOSC           = String.Empty;
                string OPIS_SKRO       = String.Empty;
                string COMPOS          = String.Empty;
                string CONSERV         = String.Empty;

                counter = dataReader["COUNTER"].ToString();
                AKT = dataReader["AKT"].ToString();
                NAZWA = dataReader["NAZWA"].ToString();
                KATEGORIA = dataReader["KATEGORIA"].ToString();
                CENA_NETTO = dataReader["CENA_NETTO"].ToString();
                STAWKA_VAT = dataReader["STAWKA_VAT"].ToString();
                CENA_SUGEROWANA = dataReader["CENA_SUGEROWANA"].ToString();
                WYPRZ = dataReader["WYPRZ"].ToString();
                COSTAM = dataReader["COSTAM"].ToString();
                D1 = dataReader["D1"].ToString();
                D2 = dataReader["D2"].ToString();
                NR_KAT = dataReader["NR_KAT"].ToString();
                DOSTEPNE_OD = dataReader["DOSTEPNE_OD"].ToString();
                COSTAM2 = dataReader["COSTAM2"].ToString();
                PROD = dataReader["PROD"].ToString();
                COSTAM3 = dataReader["COSTAM3"].ToString();
                COSTAM4 = dataReader["COSTAM4"].ToString();
                COSTAM5 = dataReader["COSTAM5"].ToString();
                ILOSC = dataReader["ILOSC"].ToString();
                OPIS_SKRO = dataReader["OPIS_SKRO"].ToString();
                COMPOS = dataReader["COMPOS"].ToString();
                CONSERV = dataReader["CONSERV"].ToString();
                //if (COMPOS.Contains(@"\"))
                //{
                //    COMPOS = "";
                //}
                StreamWriter wr = new StreamWriter(@"c:\kan\fileOuput1.txt", true);
                wr.WriteLine(
                counter + ";" +
                AKT + ";" +
                NAZWA + ";" +
                KATEGORIA + ";" +
                CENA_NETTO + ";" +
                STAWKA_VAT + ";" +
                CENA_SUGEROWANA + ";" +
                WYPRZ + ";" +
                COSTAM + ";" +
                D1 + ";" +
                D2 + ";" +
                NR_KAT + ";" +
                DOSTEPNE_OD + ";" +
                COSTAM2 + ";" +
                PROD + ";" +
                COSTAM3 + ";" +
                COSTAM4 + ";" +
                COSTAM5 + ";" +
                ILOSC + ";" +
                OPIS_SKRO + ";" +
                COMPOS + ";" +
               CONSERV + ";"
               );
                wr.Close();

And when I save it to csv file in COMPOS and CONSERV I get some garbage data, looks like combination of some fields etc :/ Do You have any idea why it's happens? And this take place for some rows, not always ...

A: 

Here are some things you can try:

  • Try checking these rows in the DB. Are they valid?
  • Do they have any special characters that are messing up the fields?
  • Debug the datareader object itself to check if the data was properly fetched, if not check your query.
Sidharth Panwar
In db these fields are empty.It's varchar fields. It's looks like I have that error only when I use Visual Studio 2010, cause in earlier version it's ok o.O
netmajor
@netmajor: do you try with newer version of Firebird ?
Hugues Van Landeghem
unfortunately company I worked don't want to use newer version of FB :/ They stay at 1.5. I am sure that in 2.0 it's should resolved...
netmajor