首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

winform调用存储过程异常

2012-08-15 
winform调用存储过程错误SQL代码SQL codeALTER PROCEDURE [dbo].[SP_T_Operation_SelectAll](@SheetType v

winform调用存储过程错误
SQL代码

SQL code
ALTER PROCEDURE [dbo].[SP_T_Operation_SelectAll](    @SheetType varchar(10),    @date1 varchar(25),    @date2 varchar(25),    @SheetOwner varchar(10),    @CostCenterCode varchar(10),    @ProductName nvarchar(100))ASBEGIN    DECLARE @sql nvarchar(MAX)    SET @sql ='            select             a.SheetID,a.OperationDate,a.SheetType,            c.ProductName,b.Quantity,b.UnitPrice,            d.UserName,b.CostCenterCode             from T_Operation a left join             T_OperationDetail b on a.SheetID=b.SheetID             left join T_Product c on b.ProductID=c.ProductID            left join T_User d on a. SheetOwner=d.UserID            where 1=1            '                IF @SheetType IS NOT NULL AND @SheetType <>''        SET @sql=@sql+' and A.SheetType ='+@SheetType;            IF @date1 IS NOT NULL AND @date1<>'' and @date2 IS NOT NULL AND @date2<>''        SET @sql=@sql+' and A.OperationDate >='+@date1+' and A.OperationDate <='+@date2;            IF @SheetOwner IS NOT NULL AND @SheetOwner<>''        SET @sql=@sql+' and d.UserName LIKE(''%'+@SheetOwner+'%'')';            IF @CostCenterCode IS NOT NULL AND @CostCenterCode<>''        SET @sql=@sql+' and B.CostCenterCode LIKE(''%'+@CostCenterCode+'%'')';            IF @ProductName IS NOT NULL AND @ProductName<>''        SET @sql=@sql+' and C.ProductName LIKE(''%'+@ProductName+'%'')';        PRINT (@sql)        EXEC (@sql)    END


传入的参数分别为1,2012/7/18 0:00:00:00,2012/7/18 0:00:00:00,,,,

[解决办法]
不过按照错误显示 你的这段
' and A.OperationDate >='+@date1+' and A.OperationDate <='+@date2;拼接出来应该是这样的
SQL code
and A.OperationDate >=012/7/18 0:00:00:00 and A.OperationDate <=2012/7/18 0:00:00:00 

热点排行