gpt4 book ai didi

mysql - Excel VBA mysql 查询字符串变量

转载 作者:行者123 更新时间:2023-11-29 15:12:40 24 4
gpt4 key购买 nike

所以我在我的 VBA 代码中从 mysql 数据库中执行这个简单的 sql 选择:

cmd.CommandText = "SELECT sum(operation_employee_execution_time) FROM employee_operation where employee_last_name like '" & sEmployee & "'"

而且它不起作用。如果我执行 msgbox(cmd.CommandText) 我会看到格式正确的 SQL 查询:

enter image description here

不幸的是,该查询的结果是什么(意味着 like 子句找不到匹配项),但是如果我像这样对变量的值进行硬编码:

cmd.CommandText = "SELECT sum(operation_employee_execution_time) FROM employee_operation where employee_last_name like 'Levkovic'"

它工作完美......

有人可以给我一些建议吗?我认为这将是某种编码问题,但将 "CharacterSet=utf8;" 添加到我的连接字符串并没有帮助(数据库中的该列是 utf8mb4_bin)

最佳答案

感谢大家的输入,问题是读取到变量 sEmployee 的 Excel 单元格包含一些 unicode 字符。

关于mysql - Excel VBA mysql 查询字符串变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59951354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com