我在我的csharp代码中有一个场景,我试图用特殊字符/和使用sql查询得到记录。csharp使用带特殊字符的sql查询
我试着在sql查询分析器中执行查询,并且在添加方括号后它工作正常。
Select * from tblDetails where name like '%[\]%' or name like '%[%]%'
但它失败时,我用它在CSHARP
string sqlQuery = "Select * from tblDetails where name like '%[/]%' or name like '%[%]%' ";
using (SqlCommand command = new SqlCommand(strQuery, strConnection))
失败如何?你有错误吗?什么是错误信息?尝试使用Profiler来查看C#程序发送的SQL命令。 –
你的代码应该可以工作。你得到的错误是什么? –
我甚至不能在SQL Management Studio中运行这个SQL查询。你确定你没有错过这里的单引号吗?或者名字像%[%]%“? – RedOctober