为1个SQL参数传递多个值 [英] Pass multiple value for 1 SQL parameter

查看:466
本文介绍了为1个SQL参数传递多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.这是我的程序

Hi. This is my procedure

create proc temp @value nvarchar(max)
as
begin
    DECLARE @sql nvarchar(max)
    set @sql = N'Select * from dbo.Categories
    where CategoryName in (' + @value +')';
    print @sql
exec sp_executesql @sql

end




我可以像这样为@value传递多个值,它可以正常工作




I can pass multiple value for @value like this and it works

temp @value = '''Beverages'',''Condiments'''



在我的窗口表单中,我有多个复选框,例如,如果复选框1& 2个被检查:



In my window form, I have multiple check boxes, for example if checkbox 1 & 2 were check:

value = "'''"+cb1.Text + "'',''" +cb2.Text + "'''" 



并通过SQL参数传递它,但是它不起作用.它不会引发任何异常,但是也不会返回任何东西.

感谢所有帮助.



and pass it through SQL parameter, but it doesn''t work.It doesn''t throw any exception but doesn''t return anything either.

Any help was appreciated.

推荐答案

我认为您在第一个参数左侧和最后一个参数右侧添加了多余的撇号. />
解决这个问题,一切正常.
I think you are putting in extra apostophe''s on the left of your first parameter and the right of your last parameter.

Fix that and things should work.


感谢您的回复,但我不这样认为,因为它在SQL中可以正常工作.我只是不知道为什么它在我的winform上不起作用
Thanks for replying but I don''t think so because it works fine in SQL. I just don''t figure out why it doesn''t work on my winform


这篇关于为1个SQL参数传递多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆