浏览记录的储存过程怎么写

来源:百度知道 编辑:UC知道 时间:2024/06/23 18:18:40
做一个用户浏览商品记录功能。
用Cookie保存商品id,多个商品用,号分隔。
Cookie里面内容:id1,id2等。
储存过程:
CREATE Procedure Cookies
@IdList NVarChar(50)
as
select * from Table1 where id in (@IdList)
GO
Table1的id字段是int型。
C#读出Cookie内容并把读出的内容当参数传到@IdList,
执行页面报错,将 nvarchar 值 '2,6' 转换为数据类型为 int 的列时发生语法错误。
这个储存过程怎么写?
不用储存过程就不会报错。

改一改
CREATE Procedure Cookies
@IdList NVarChar(50)
as
declare @sql nvarchar(1000)
set @sql = 'select * from Table1 where id in (' + @IdList + ')'
EXEC(@sql)
GO

这样应该可以,但是会有注入漏洞。。。