views:

470

answers:

1

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.

A: 

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
Viktor Jevdokimov
How will the thread culture affect the character encoding? There is a TextInfo property of the CultureInfo but it only deals with code pages.
Manga Lee
Let say your current runtime culture is Unicode or UTF-8 or any else. .NET will convert everything coming to it to Unicode to store internally in memory and convert back using current culture when outputing. So changing current thread culture says to .NET how to do conversions for input/output.
Viktor Jevdokimov