为什么以下存储过程会在.net c#中导致问题,它基本上用于屏幕上的收益报告的性质只读当我勾选传递开始日期和结束日期的空值但尝试执行时,它在 sql server 中工作正常在我的适配器填充下面相同,它会引发异常
程序 :
public virtual EmployeeBenefitDataset GetBenefitsRecords(int id)
{
try
{
EmployeeBenefitDataset ds = new EmployeeBenefitDataset();
using (BenefitTableAdapter adpt = new BenefitTableAdapter())
{
adpt.Connection.ConnectionString = DataAccessLogicHelper.PamsConnectionString;
adpt.Fill(ds.BenefitRecords, id, 4, null,null);
}
return ds;
}
catch (Exception ex)
{
Logger.ErrorEntry(ex);
throw ex;
}
存储过程
GO
/****** Object: StoredProcedure [dbo].[hms_GetBenefitRecordsDetails] Script Date: 09/09/2013 14:09:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[hms_GetBenefitRecordsDetails]
(
@empno int,
@type int,
@stardate datetime,
@enddate datetime
)
AS
SET NOCOUNT ON;
IF NOT @stardate IS NULL
begin
SELECT benefit.emp_no, benefit.record_id, benefit.contract_id, benefit.career_id, benefit.date_from, benefit.date_to, benefit.benefit_type, benefit.monthly_value,
benefit.benefit_provider, benefit.level_of_cover, benefit.previous_monthly_cost, benefit.benefit_change_details, benefit.current_benefit, benefit.notes,
benefit.level_description, benefit.monthly_annual, benefit.cover_level, benefit.qualifying_reason, benefit_cover_level.desc_ AS benefitcoverdescription,
benefit_provider.desc_ AS benefitproviderdescription,benefit_type.desc_ as benefittypedescription ,employee.benefit_annual_amount,employee.benefit_salary_option,employee.benefit_value
FROM benefit INNER JOIN
benefit_cover_level ON benefit.cover_level = benefit_cover_level.code INNER JOIN
benefit_provider ON benefit.benefit_provider = benefit_provider.code INNER JOIN
benefit_type ON benefit.benefit_type = benefit_type.code
INNER JOIN employee on benefit.emp_no = @empno
where benefit.emp_no= @empno or employee.emp_no= benefit.emp_no
and benefit.benefit_type = @type
end
else
begin
SELECT benefit.emp_no, benefit.record_id, benefit.contract_id, benefit.career_id, benefit.date_from, benefit.date_to, benefit.benefit_type, benefit.monthly_value,
benefit.benefit_provider, benefit.level_of_cover, benefit.previous_monthly_cost, benefit.benefit_change_details, benefit.current_benefit, benefit.notes,
benefit.level_description, benefit.monthly_annual, benefit.cover_level, benefit.qualifying_reason, benefit_cover_level.desc_ AS benefitcoverdescription,
benefit_provider.desc_ AS benefitproviderdescription,benefit_type.desc_ as benefittypedescription ,employee.benefit_annual_amount,employee.benefit_salary_option,employee.benefit_value
FROM benefit INNER JOIN
benefit_cover_level ON benefit.cover_level = benefit_cover_level.code INNER JOIN
benefit_provider ON benefit.benefit_provider = benefit_provider.code INNER JOIN
benefit_type ON benefit.benefit_type = benefit_type.code
INNER JOIN employee on benefit.emp_no = @empno
where benefit.emp_no= @empno and employee.emp_no= benefit.emp_no
end
IF NOT @stardate IS NULL
begin
SELECT benefit.emp_no, benefit.record_id, benefit.contract_id, benefit.career_id, benefit.date_from, benefit.date_to, benefit.benefit_type, benefit.monthly_value,
benefit.benefit_provider, benefit.level_of_cover, benefit.previous_monthly_cost, benefit.benefit_change_details, benefit.current_benefit, benefit.notes,
benefit.level_description, benefit.monthly_annual, benefit.cover_level, benefit.qualifying_reason, benefit_cover_level.desc_ AS benefitcoverdescription,
benefit_provider.desc_ AS benefitproviderdescription,benefit_type.desc_ as benefittypedescription ,employee.benefit_annual_amount,employee.benefit_salary_option,employee.benefit_value
FROM benefit INNER JOIN
benefit_cover_level ON benefit.cover_level = benefit_cover_level.code INNER JOIN
benefit_provider ON benefit.benefit_provider = benefit_provider.code INNER JOIN
benefit_type ON benefit.benefit_type = benefit_type.code
INNER JOIN employee on benefit.emp_no = @empno
where benefit.emp_no= @empno and employee.emp_no= benefit.emp_no and
benefit.benefit_type = @type and
benefit.date_from >= @stardate and benefit.date_to <= @enddate
end