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

吃可爱长大的小学妹 提交于 2019-12-08 09:19:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!