OdbcConnection Text Driver ignores scheme.ini settings

♀尐吖头ヾ 提交于 2020-01-14 04:34:06

问题


Here is my code:

            OdbcConnection conn = new OdbcConnection("Driver={Microsoft Text Driver (*.txt; *.csv)};DSN=scrapped.csv");
        conn.Open();
        OdbcCommand foo = new OdbcCommand(@"SELECT * FROM [scrapped.csv] WHERE KWOTA < 100.00", conn);
        IDataReader dr = foo.ExecuteReader();
        StreamWriter asd = new StreamWriter("outfile.txt");
        while (dr.Read())
        {
            int cols = dr.GetSchemaTable().Rows.Count;
            for (int i = 0; i < cols; i++)
            {
                asd.Write(string.Format("{0};",dr[i].ToString()));
            }
            asd.WriteLine();
        }
        asd.Flush();
        asd.Close();
        dr.Close();
        conn.Close();

Here is my Scheme.ini

      [scrapped.csv]

Format=Delimited(;)
NumberDigits=2
CurrencyThousandSymbol= 
CurrencyDecimalSymbol=,
CurrencyDigits=2

Col1=DataOperacji Date
Col2=DataKsiegowania Date
Col3=OpisOperacji Text
Col4=Tytul Text
Col5=NadawcaOdbiorca Text
Col6=NumerKonta Text
Col7=Kwota Currency
Col8=SaldoPoOperacji Currency

Here I have sample from my CSV:

2013-01-22;2013-08-24;notmatter;"notmatter";"notmatter";'notmatter';7 111,55;10 222,20;
2013-03-26;2013-08-23;notmatter;"notmatter";"notmatter";'notmatter';-275,00;15 466,24;

So even if I have date and currency set in scheme.ini and regional settings (which should be used by odbc by defult but are not) values which i write to output file are total mess.

They are empty if there is space (my local thousend delimiter) and if I have value like 15,45 i got 15,4500 instead.

Date fields also behave abnormal, and even if I insert to scheme.ini DateTimeFormat I get nothing like I specified in format.

Any help would be appreciated, what to do with it, I would like to use ODBC and query CSV data like database with WHERE something = something


回答1:


I added a line to your schema.ini and ran against an adodb connection and it worked for me in the matter of dates, other bits are still not right. Note DateTimeFormat.

[scrapped.csv]
Format=Delimited(;)
NumberDigits=2
CurrencyThousandSymbol= 
CurrencyDecimalSymbol=,
CurrencyDigits=2
DateTimeFormat="yyyy-mm-dd"

Col1=DataOperacji Date
Col2=DataKsiegowania Date
Col3=OpisOperacji Text
Col4=Tytul Text
Col5=NadawcaOdbiorca Text
Col6=NumerKonta Text
Col7=Kwota Currency
Col8=SaldoPoOperacji Currency

You may also need:

ColNameHeader=False
MaxScanRows=0

But at the moment, I cannot see a way to get a space accepted as the CurrencyThousandSymbol



来源:https://stackoverflow.com/questions/12108500/odbcconnection-text-driver-ignores-scheme-ini-settings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!