OdbcConnection文本驱动程序忽略scheme.ini设置 [英] OdbcConnection Text Driver ignores scheme.ini settings
问题描述
下面是我的代码:
OdbcConnection康恩=新OdbcConnection(驱动程序= {Microsoft文本驱动程序(* .TXT; * .csv的)}; DSN = scrapped.csv);
conn.Open();
的OdbcCommand富=新的OdbcCommand(@SELECT * FROM [scrapped.csv]其中KWOTA< 100.00,康恩);
的IDataReader博士= foo.ExecuteReader();
的StreamWriter ASD =新的StreamWriter(outfile.txt);
,而(dr.Read())
{
INT COLS = dr.GetSchemaTable()Rows.Count。
的for(int i = 0; I< COLS;我++)
{
asd.Write(的String.Format({0};博士[I]的ToString() ));
}
asd.WriteLine();
}
asd.Flush();
asd.Close();
dr.Close();
conn.Close();
下面是我的Scheme.ini
[scrapped.csv]
格式=(;)分隔
NumberDigits = 2
CurrencyThousandSymbol =
CurrencyDecimalSymbol =,
CurrencyDigits = 2
COL1 = DataOperacji日期
col2的= DataKsiegowania日期
COL3 = OpisOperacji文本
COL4 = Tytul文本
COL5 = NadawcaOdbiorca文本
COL6 = NumerKonta文本
COL7 = Kwota货币
Col8 = SaldoPoOperacji货币
在这里,我有样从我的CSV:
2013年1月22日; 2013年8月24日; notmatter;notmatter ;notmatter;'notmatter'; 7 111,55 10 222,20;
2013年3月26日; 2013年8月23日; notmatter;notmatter;notmatter;'notmatter'; - 275,00; 15 466,24;
所以,即使我有scheme.ini和区域设置日期和货币集(应该使用由defult ODBC但)这是我写的输出文件的值是一团糟。
它们是空的,如果有空间(我的地方thousend分隔符),如果我有像15,45的价值,我得到15,4500代替。
日期领域也表现异常,即使我插到scheme.ini DateTimeFormat
我什么也没得到像我在格式中指定。
任何帮助,将不胜感激,有什么用它做什么,我想用ODBC和查询如数据库CSV数据与 WHERE东西=东西
解决方案
我添加
[scrapped.csv]
格式=(;)分隔
NumberDigits = 2
CurrencyThousandSymbol =
CurrencyDecimalSymbol =,
CurrencyDigits = 2
DateTimeFormat =YYYY-MM-DD
COL1 = DataOperacji日期
col2的= DataKsiegowania日期
COL3 = OpisOperacji文本
COL4 = Tytul文本
COL5 = NadawcaOdbiorca文本
COL6 = NumerKonta文本
COL7 = Kwota货币
Col8 = SaldoPoOperacji货币
您可能还需要:
ColNameHeader =假
的MaxScanRows = 0
但在那一刻,我看不到的方式来获得接纳为CurrencyThousandSymbol
空间
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
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
这篇关于OdbcConnection文本驱动程序忽略scheme.ini设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!