问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/1475821/how-can-i-specify-the-character-encoding-to-be-used-by-oledb-when-querying-a-dbf