VBA ADODB Query Mysql returns character corruption

自作多情 提交于 2020-01-30 13:13:45

问题


Sub hh()
Dim sql As String
Dim rs As New ADODB.Recordset
Dim con As ADODB.Connection
Dim dbConnStr As String
dbConnStr = "Driver={MySQL ODBC 5.2 ANSI DRIVER}; SERVER=localhost; DATABASE=landscape; USER=root; PASSWORD=mypass;"
Set con = New ADODB.Connection
con.Open dbConnStr
sql = "SELECT '東京都' AS tokyou"
rs.Open sql, con
Debug.Print rs!tokyou
rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
End Sub


Returns things like "東・ "

I've tried:
1. use adodb.stream to convert query string to utf8, or otherwise convert query result to unicode
2. excute "set names = unicode;" in query
3. add "charset=unicode;" in connection string while open database connection

but none of them works, could you please help me, thanks!

回答1:


It looks like you are using UNICODE characters. Please note that the ODBC driver comes in two flavours: ANSI and UNICODE. The latter is more appropriate to your situation. Use MySQL ODBC UNICODE Driver and you'll be good. Arigatou!



来源:https://stackoverflow.com/questions/25777214/vba-adodb-query-mysql-returns-character-corruption

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