SQLCommand问题查看 [英] SQLCommand question to view
本文介绍了SQLCommand问题查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我对C#SQLCommand有疑问.
这是我要运行的SQL查询:
Hello everyone,
i have a question for the C# SQLCommand.
this is my SQL query to be run :
string s = "Select * from Country where Countrycode like @Code"
Sqlcommand cmd = new sqlcommand(s,sqlcon);
cmd.parameters.addwithvalue(@Code,value);
cmd.executenonquery();
在这里我无法得到结果,我认为是参数问题.
所以我用
改变了@code
here i cant get the result, i think is the parameter problem.
so i change the @code
by using
string s = "Select * from Country where Countrycode like '%"+ Code +"%'"
它正在工作.
可以告诉我参数的错误在哪里?
it is working.
can tell me where is my mistake for the parameter?
推荐答案
您可以在使用Like
子句的同时使用它
You can use this while usingLike
clause
command.Parameters.AddWithValue("@Code","%" + value + "%");
cmd.executenonquery();不会返回结果集.尝试使用数据读取器或数据适配器.
cmd.executenonquery(); will not return you the result set. Try to use data reader or data adapter.
检查数据中是否有任何前导或尾随空格.如果是这样,使用LTrim(RTrim(Countrycode)) like @Code
会很好用.
Check for any leading or trailing blank spaces in your data. If that is the case, using LTrim(RTrim(Countrycode)) like @Code
will work fine.
这篇关于SQLCommand问题查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文