当前位置: 代码迷 >> ASP.NET >> winform调用存储过程异常
  详细解决方案

winform调用存储过程异常

热度:9143   发布时间:2013-02-25 00:00:00.0
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
  相关解决方案