为什么参数不起作用?请大虾指点.
我想进行模糊查询,把其中的参数传递后,结果为0,请大虾告诉我like中在asp.net(c#)如何传递参数.SELECT DeleteDate, DeleteIP, DeleteRen, DeleteStatus, FileName, FileShuoMing, ServerFilePath, ShenHe, ShenHeDate,ShenHeIP, ShenHeRen, UploadFileTime, UserName, id
FROM T_UploadFile
WHERE (FileName LIKE '%' + @FileName + '%') AND (FileShuoMing LIKE '%' + @FileContent + '%') AND (ShenHe = '1') AND (DeleteIP = '0')
--------------------编程问答-------------------- sql2005可以这样写 sql2000不行 要拼sql
还不如就拼sql 通用行更强 过滤下参数即可 --------------------编程问答-------------------- WHERE (FileName LIKE '%' + @FileName + '%') AND (FileShuoMing LIKE '%' + @FileContent + '%') AND (ShenHe = '1') AND (DeleteIP = '0')
=>
WHERE (FileName LIKE '%@FileName%') AND (FileShuoMing LIKE '%@FileContent%') AND (ShenHe = '1') AND (DeleteIP = '0')
--------------------编程问答--------------------
如果那几个@FileName什么的是字符串类型的,sql语句没什么问题,你条件那么多,你看看是不是没有数据满足上述条件?
--------------------编程问答--------------------
CREATE TABLE A
(
a01 INT,
a02 VARCHAR(10)
)
INSERT INTO A
SELECT 1,'haha' UNION ALL
SELECT 2,'gaga' UNION ALL
SELECT 3,'jiji'
DECLARE @var VARCHAR(10)
SET @var='C'
SELECT * FROM A WHERE a02 LIKE '%'+@var+'%'
/*
a01 a02
----------- ----------
1 cc
(所影响的行数为 1 行)
*/
不好意思,有点错,重贴一下
CREATE TABLE A
(
a01 INT,
a02 VARCHAR(10)
)
INSERT INTO A
SELECT 1,'haha' UNION ALL
SELECT 2,'gaga' UNION ALL
SELECT 3,'jiji'
DECLARE @var VARCHAR(10)
SET @var='h'
SELECT * FROM A WHERE a02 LIKE '%'+@var+'%'
/*
a01 a02
----------- ----------
1 haha
(所影响的行数为 1 行)
*/
--------------------编程问答--------------------
我用的是2000数据库. --------------------编程问答--------------------
我上面给的2000也行啊,我试过的
补充:.NET技术 , ASP.NET