[英].Net Connector for MySQL - Parameter
I have a datatable, containing two rows: id char(9), eh char(4). 我有一个数据表,其中包含两行:id char(9),eh char(4)。 Both rows contains numeric values (I can't change this), for example 123456789.
两行都包含数字值(我无法更改),例如123456789。
The query SELECT id,eh FROM tab WHERE id LIKE '123456789' directly in the MySQL-client works fine, in VB.net too. 直接在MySQL客户端中的查询SELECT id,eh FROM选项卡WHERE id LIKE'123456789'在VB.net中也可以正常工作。
But if I use a parameter in VB.net instead of building the query-string, the query returns null rows. 但是,如果我在VB.net中使用参数而不是构建查询字符串,则查询返回空行。 This is what I've done (not the complete code):
这是我所做的(不是完整的代码):
Dim com As New MySqlCommand
com.CommandText = "SELECT id,eh FROM tab WHERE id LIKE @i"
com.Parameters.Add("@i", MySqlDbType.VarChar)
com.Parameters("@i").Value = number
I think, the connector does not send the quotes of the string (maybe because there are only numbers), because if I change the first query in the MySQL-client to ... LIKE 123456789, I get null rows, too. 我认为,连接器不会发送字符串的引号(可能是因为只有数字),因为如果我将MySQL客户端中的第一个查询更改为...就像123456789一样,我也会得到空行。
Do you have any hints or workarounds for me? 您对我有什么提示或解决方法吗?
Try 尝试
MySqlDbType.String
As your parameter type. 作为您的参数类型。
Note.. I do not use MySql but a quick google came up with char as a string. 注意..我不使用MySql,但是一个快速的Google用char作为字符串。
EDIT 编辑
Maybe you are missing the Apostrophes around you @i 也许您错过了@i附近的使徒
com.CommandText = "SELECT id,eh FROM tab WHERE id LIKE '@i'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.