-2

次のストアド プロシージャが .net c# で問題を引き起こすのはなぜですか。基本的には、画面上の利益のレポートの性質のために読み取り専用で使用されます。私のアダプターの塗りつぶしでも同じで、例外がスローされます

手順 :

    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 
4

3 に答える 3

1

チェックボックスを選択してnull値を渡すとNULL、パラメータとともに値が明示的に渡されます。現在のコードでは、パラメーターを渡していないため、例外が発生します。

現在の形式では、ストアド プロシージャはNULLstartdate と enddate の値を受け入れる準備ができていないため、プロシージャを次のように変更する必要があります。

@stardate datetime  = NULL, 
@enddate datetime = NULL

NULL DateTimeC# から渡すには、値をサポートするDateTime?orを使用します。Nullable<DateTime>Null

于 2013-09-09T13:17:33.393 に答える