如何指定查询一个DBF时要使用的OLEDB的字符编码​​?时要、字符、DBF、OLEDB

2023-09-04 05:17:40 作者:寒笙

是否可以指定字符编码应查询一个DBF文件时所需的OLEDB?

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

一个可能的解决方法是将EN code中的OLEDB调用DBF文件的字符编码​​前的查询字符串,然后连接$ C C所有返回时,他们的结果$。这将工作,但它会很好,如果OLEDB或ADO.NET可能会帮我这个忙。

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.

更新

的suggestion维克托·Jevdokimov似乎并没有自动工作。但是,这让我调查的字符串手动转换。它可以使用的CultureInfo的TextInfo中属性找出OEM codePAGE和Windows codePAGE并使用它们来获得相应的编码实例来执行手动转换。但我不能让ADO.NET使用这些encondings来执行转换对我来说。

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.

推荐答案

执行DBF SQL更改CurrentThread的的CurrentCulture,然后恢复之前:

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