我已经使用参数化查询并没有问题,但是今天我遇到了一个我无法调试的错误。 这是我工作的查询带有参数不起作用的Vb 2015查询
cmd.CommandText = "select idcliente, ragsociale from Clienti where idcliente =" & strName & " or codiceamministrazione='" & strName & "' or piva='" & strName & "' or codfisc='" & strName & "'"
相同,但参数,而不是基于内部ID或商业工作
cmd.CommandText = "select idcliente, ragsociale from Clienti where idcliente = @Cliente or [email protected] or [email protected] or [email protected]"
cmd.Parameters.AddWithValue("@Cliente", strName)
我自动完成过程中使用此,显示了客户端的名称许可证号码(和其他类似的代码)。在数据库客户端记录可以有所有的代码字段编译或只是1.
随着非参数化查询自动完成建议弹出,与参数化的一个没有显示。没有错误。
编辑: 使用相同的功能这
cmd.Parameters.Add("@Cliente", SqlDbType.VarChar)
cmd.Parameters("@Cliente").Value = strName
现在另一个查询(semplicity前省略)的作品,但是,自叹不如,一个为我所做的这个问题没有。
工作:
cmd.CommandText = "select idcliente, ragsociale from Clienti where ragsociale like '%'[email protected]+'%' or [email protected]"
仍无法正常工作:
cmd.CommandText = "select idcliente, ragsociale from Clienti where idcliente = @Cliente or [email protected] or [email protected]"
你知道你可以将其重写为'where @Cliente in(idcliente,codiceamministrazione,piva,codfisc)' –
请不要使用.AddWithValue!我认为,这是问题所在。 – muffi
[Joel Coehoorn的博客文章](https://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using-addwithvalue-already/)重申muffi的言论。 –