Exception creating csv file

T

Tommaso Caldarola

International settings: Italian

Excecuting the following snippet

System.Data.OleDb.OleDbConnection Conn=new
System.Data.OleDb.OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\;Extended
Properties=\"text;HDR=Yes;FMT=Delimited\""
System.Data.OleDb.OleDbCommand Cmd = new
System.Data.OleDb.OleDbCommand("create table file1.csv ([column1]
char(255), [column2] char(255), [column3] char(255))"Cnn);
Cnn.Open();
Cmd.ExecuteNonQuery();

I got this exception:

[System.Data.OleDb.OleDbException]:
{"Text file specification field separator matches decimal separator or
text delimiter." }

If I set English as International Settings no exception occurs.
 
N

Nicholas Paldino [.NET/C# MVP]

Tommaso,

The reason this happens is probably because of your culture settings.
The culture settings for Italian probably use a comma as a decimal separator
for numbers, and it is getting confused.

You might have to parse the file by hand, since I don't know how to
override the culture settings for the driver in OLEDB.
 
R

rossum

International settings: Italian

Excecuting the following snippet

System.Data.OleDb.OleDbConnection Conn=new
System.Data.OleDb.OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\;Extended
Properties=\"text;HDR=Yes;FMT=Delimited\""
System.Data.OleDb.OleDbCommand Cmd = new
System.Data.OleDb.OleDbCommand("create table file1.csv ([column1]
char(255), [column2] char(255), [column3] char(255))"Cnn);
Cnn.Open();
Cmd.ExecuteNonQuery();

I got this exception:

[System.Data.OleDb.OleDbException]:
{"Text file specification field separator matches decimal separator or
text delimiter." }

If I set English as International Settings no exception occurs.
It looks to me like the application is getting confused between the
Italian decimal separator ',' and the comma that separates the
variables when you are storing a double or a float. The solution may
well be to enclose the field in double quotes so the output is
"123,456", rather than 123,456, which is 123.456, in English which is
why it is OK.

This may mean setting up an extra column for each float/double field
and population it with '"' + 123,456.ToString() + '"' or something
similar.

rossum
 
T

Tommaso Caldarola

Nicholas said:
Tommaso,

The reason this happens is probably because of your culture settings.
The culture settings for Italian probably use a comma as a decimal separator
for numbers, and it is getting confused.

You might have to parse the file by hand, since I don't know how to
override the culture settings for the driver in OLEDB.

Update:

the problem occurs on SO english with Italian settings only
while on SO and settings both in English or Italian no problem.
 
T

Tommaso Caldarola

Tommaso said:
Update:

the problem occurs on SO english with Italian settings only
while on SO and settings both in English or Italian no problem.

Fixed. Just to provide in the destination folder a schema.ini file with these
settings:

CharacterSet=ANSI
CurrencyThousandSymbol=,
DecimalSymbol=.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top