Magnus Lindhe
Magnus Lindhe

Reputation: 7317

How can I specify the character encoding to be used by OLEDB when querying a DBF?

Is it possible to specify which character encoding should be used by OLEDB when querying a DBF file?

A possible work-around would be to encode the query string before the OLEDB call to the DBF file's character encoding and then encode all the results when they are returned. This will work but it would be nice if OLEDB or possibly ADO.NET could do this for me.

UPDATE

The suggestion by Viktor Jevdokimov does not seem to work automatically. But it made me investigate manual conversion of the strings. It is possible to use the TextInfo property of CultureInfo to find out the OemCodePage and the WindowsCodePage and use those to get the corresponding Encoding instances to perform manual conversion. But I can not get ADO.NET use these encondings to perform the conversion for me.

Upvotes: 1

Views: 2489

Answers (1)

Viktor Jevdokimov
Viktor Jevdokimov

Reputation: 1056

Before executing DBF SQL I change CurrentThread's CurrentCulture and restore thereafter:

Dim appCulture As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US")
//execute command here
System.Threading.Thread.CurrentThread.CurrentCulture = appCulture

Upvotes: 2

Related Questions