Click here to Skip to main content
15,314,594 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
error=>The parameterized query '(@IsFilterDates bit,@IsFilterDocumentNumbers bit,@EnterpriseIds ' expects the parameter '@FilterFromDocumentNumbers', which was not supplied..


C#
public virtual ActionResult GetReportSnapshot()
   {
      var data = (ComparativeBalanceReportDS) Session["ComparativeSession"];
       StiReport report = new StiReport();
       report.Dictionary.DataStore.Clear();
       switch (data.NatureReportIdLevel)
       {
           case 1:
               report.Load(Server.MapPath("~/Content/StimulReports/group.mrt"));
               break;
           case 2:
               report.Load(Server.MapPath("~/Content/StimulReports/total.mrt"));
               break;
           case 3:
               report.Load(Server.MapPath("~/Content/StimulReports/ledger.mrt"));
               break;
           case 4:
               report.Load(Server.MapPath("~/Content/StimulReports/sampr.mrt"));
               if (data.IsNumberFilter != false)
               {
                   report["@FilterFromDocumentNumbers"] = data.NumberFilter.FromDocumentDocumentNumber;
                   report["@FilterToDocumentNumbers"] = data.NumberFilter.ToDocumentDocumentNumber;

               }
               else
               {

                   report["@FilterFromDocumentNumbers"] = null;
                   report["@FilterToDocumentNumbers"] = null;

               }
                            report["@IsFilterDates"] = data.IsDateFilter;
                   report["@IsFilterDocumentNumbers"] = data.IsNumberFilter;
                   report["@EnterpriseIds"] = data.EnterpriseId;
                   report["@FilterFromDates"] = data.DateFilter.FromDocumentDate.Value;
                   report["@FilterToDates"] = data.DateFilter.ToDocumentDate.Value;

                   report["@BaseCompareIds"] = data.BaseCompareId;
                   report["@NatureReportIdLevels"] = data.NatureReportIdLevel;


               break;

       }



and sometimes some of parameters is null

report["@FilterFromDates"] = null;
report["@FilterToDates"] = null;


SQL
   Create function [dbo].[DetailFunction](@IsFilterDates bit,
                 @IsFilterDocumentNumbers bit,
                 @EnterpriseIds uniqueidentifier,
                 @FilterFromDates datetime,
                 @FilterToDates datetime,
                 @FilterFromDocumentNumbers int= null,
                 @FilterToDocumentNumbers int= null,
                 @BaseCompareIds int,
                 @NatureReportIdLevels int
                )
  returns @results table (
                  MonthOfDocumentItem nvarchar(20),
                   DetailAccountId nvarchar(50),
                    CreditDebit decimal,
                    Title nvarchar(150)
                                 ) as
begin

  if @IsFilterDates=1 and @IsFilterDocumentNumbers = 1 and @BaseCompareIds = 2 and @NatureReportIdLevels = 4
  begin
    insert @results (MonthOfDocumentItem,CreditDebit,DetailAccountId,Title)
    Select  [MonthOfDocumentItem],[CreditDebit],DetailAccountId,Title
    From FilterDetailDocumentItemWithDateAndNumber(@EnterpriseIds,@FilterFromDates,@FilterToDates,@FilterFromDocumentNumbers,@FilterToDocumentNumbers)
  end
  else if @IsFilterDates=1 and @IsFilterDocumentNumbers = 0 and @BaseCompareIds= 2 and @NatureReportIdLevels = 4
  And @FilterFromDocumentNumbers is null And @FilterToDocumentNumbers is null
  begin
    insert @results (MonthOfDocumentItem,CreditDebit,DetailAccountId,Title)
    Select  [MonthOfDocumentItem],[CreditDebit],DetailAccountId,Title
    From FilterDetailDocumentItemWithDate(@EnterpriseIds,@FilterFromDates,@FilterToDates)
  end
  else if @IsFilterDates=0 and @IsFilterDocumentNumbers = 1 and @BaseCompareIds = 2 and @NatureReportIdLevels = 4
  begin
    insert @results (MonthOfDocumentItem,CreditDebit,DetailAccountId,Title)
    Select  [MonthOfDocumentItem],[CreditDebit],DetailAccountId,Title
    From FilterDetailDocumentItemWithDocumentNumber(@EnterpriseIds,@FilterFromDocumentNumbers,@FilterToDocumentNumbers)
  end
  if @IsFilterDates= 0 and @IsFilterDocumentNumbers = 0 and @BaseCompareIds = 2 and @NatureReportIdLevels = 4

  begin
    insert @results (MonthOfDocumentItem,CreditDebit,DetailAccountId,Title)
    Select  [MonthOfDocumentItem],[CreditDebit],DetailAccountId,Title
    From FilterDetailDocumentItemWithoutDateAndNumber(@EnterpriseIds)
  end
  return
          end




How do I send null values to my report to exec stored procedure?

My stored procedure does work when some of parameters are null, because I handle in T-SQL, but does not work when run in project.
Posted
Updated 2-Nov-13 22:52pm
v4
Comments
roozbeh heydari 3-Nov-13 6:22am
   
answer=> use dbNull.Value

1 solution

Just putting it here so that this stops being unanswered - the other guy is right. DBNull.value is not null, it's null in the DB. Confusing, I know, but null in DBs does have totally different behaviours to null in C#.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900