Solved

export procedure not working when i use parameters

Posted on 2004-08-23
29
605 Views
Last Modified: 2008-01-09
Hello all,
I have decided to repost this question to get some new ideas.  I am passing two dates from a visual studio.net webform unto a crystal report and that part works fine.  I have the two parameters set up as dates and i am passing dates into them.  My only problem now, is that i get an error when i try to export the crystal report to a pdf file.  Here is the error.  I have gotten a lot of insight but i can not get passed this error.  If i take the parameters off of the report the export works fine.

Server Error in '/tool/Tool128' Application.
--------------------------------------------------------------------------------

Missing parameter field current value.

Stack Trace:

[ParameterFieldCurrentValueException: Missing parameter field current value.]
   .~(String L, EngineExceptionErrorID M)
   .z(String F, Int32 G)
   CrystalDecisions.CrystalReports.Engine.FormatEngine.internalSetReportInfo(RequestContext reqContext)
   CrystalDecisions.CrystalReports.Engine.FormatEngine.internalGetViewContext(ReportPageRequestContext reqContext, PEViewContextW* viewContext)
   CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)
   CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
   CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
   Tool128.CrystalView.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\tool\tool128\CrystalView.aspx.vb:83
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   System.Web.UI.Page.ProcessRequestMain()

 
0
Comment
Question by:tentavarious
  • 13
  • 12
  • 2
  • +1
29 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 11873185
Are you exporting from the viewer or from code.

If it is from code then please post the code.

mlmcc
0
 

Author Comment

by:tentavarious
ID: 11874661
Ok this code is within my CrystalReport.aspx.vb web form

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Not Page.IsPostBack Then
        addparameters()
        End If
    End Sub

    Sub addparameters()
        Dim startdate As Date
        Dim enddate As Date
        startdate = Session("StartDate")
        enddate = Session("EndDate")

        Dim paramFields As New ParameterFields
        Dim paramField As New ParameterField
        Dim paramfield2 As New ParameterField
        Dim discreteVal As New ParameterDiscreteValue
        Dim discreteval2 As New ParameterDiscreteValue
        paramField.CurrentValues.Clear()
        paramField.ParameterFieldName = "thru"
        discreteVal.Value = startdate
        paramField.CurrentValues.Add(discreteVal)
        paramFields.Add(paramField)
        paramfield2.CurrentValues.Clear()
        paramfield2.ParameterFieldName = "from"
        discreteval2.Value = enddate
        paramfield2.CurrentValues.Add(discreteval2)
        paramFields.Add(paramfield2)
        CrystalReportViewer1.ParameterFieldInfo = paramFields
        CrystalReportViewer1.ReportSource = "c:\inetpub\wwwroot\tool\tool128\CrystalReport1.rpt"
        CrystalReportViewer1.DataBind()
    End Sub
    'export to pdf
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myexportoptions As CrystalDecisions.Shared.ExportOptions
        Dim mydiskfile As CrystalDecisions.Shared.DiskFileDestinationOptions
        Dim myexportfile As String
        Dim myReport As New CrystalReport1
        myexportfile = "c:\inetpub\wwwroot\tool\tool128\misc" & Session.SessionID.ToString & ".pdf"
        mydiskfile = New CrystalDecisions.shared.DiskFileDestinationOptions
        mydiskfile.DiskFileName = myexportfile
        myexportoptions = myReport.ExportOptions
        With myexportoptions
            .DestinationOptions = mydiskfile
            .ExportDestinationType = .ExportDestinationType.DiskFile
            .ExportFormatType = .ExportFormatType.PortableDocFormat
        End With

        myReport.Export()
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "application/pdf"
        Response.WriteFile(myexportfile)
        Response.Flush()
        Response.Close()
        System.IO.File.Delete(myexportfile)
    End Sub
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11875374
I got you.

Your problem is you are trying to use viewer objetc to set parameetrs then using report object model to do exporting. Use the same method to do both actions. Then you wont receive this error message

I will recommend using report engine object model because it goives more capability to you as a developer

Regards
Emre
0
 

Author Comment

by:tentavarious
ID: 11882241
Could you elaborate on how, i am new to crystal reports, how can i use the same method to do both actions?
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11882254
which method do you want to use. Are you going with the engine model
0
 

Author Comment

by:tentavarious
ID: 11882994
I am not sure what you are asking by engine model.  I would like to use whatever model will make this work.  I need to have the start date and end date show up on the report and the only way i know how to put them there is by using the code i have above.  The code works fine to put the parameters on the report i just cant export the report anymore.  I have tried using the code below to add a parameter and i get an error when the page loades.

 Dim crReport As New CrystalReport1

        'ParameterFieldDefinitions and ParameterFieldDefinition are off the
        'CrystalDecisions.CrystalReports.Engine Namespace
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition

        'ParameterValues and ParameterDiscreteValue are off the CrystalDecisions.Shared
        'namespace
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        'Set Date Parameter

        'Set discrete value
        crParameterDiscreteValue.Value = CDate("8/19/2005")

        'Access first parameter field definition
        crParameterFieldDefinitions = crReport.DataDefinition.ParameterFields
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("DateParam")

        ' Add parameter value
        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterValues.Add(crParameterDiscreteValue)

        ' Apply the current value to the parameter definition
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)


        CrystalReportViewer1.ReportSource = "c:\inetpub\wwwroot\tool\tool128\CrystalReport1.rpt"
        CrystalReportViewer1.DataBind()
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11883116
you said there are 2 parameters and your code only adds one parameetr. Second parameter is not getting added. Thta is why you are getting the error


you are using the viewer object model then ok correct your parameter code like this

Dim crReport As New CrystalReport1

        'ParameterFieldDefinitions and ParameterFieldDefinition are off the
        'CrystalDecisions.CrystalReports.Engine Namespace
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition

        'ParameterValues and ParameterDiscreteValue are off the CrystalDecisions.Shared
        'namespace
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        'Set Date Parameter

        'Set discrete value
        crParameterDiscreteValue.Value = CDate("8/19/2005")

        'Access first parameter field definition
        crParameterFieldDefinitions = crReport.DataDefinition.ParameterFields
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("DateParam")

        ' Add parameter value
        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterValues.Add(crParameterDiscreteValue)
       crParameterFieldDefinition = crParameterFieldDefinitions.Item("DateParamEnd")

        ' Add parameter value
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterDiscreteValue.Value = CDate("8/21/2005")
        crParameterValues.Add(crParameterDiscreteValue)

        ' Apply the current value to the parameter definition
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
'export code here

CrystalReportViewer1.export code here my vb.net is not open but you have to set it from
Crystalviewer1.
use intelisense to find the export method.It is there

        CrystalReportViewer1.ReportSource = "c:\inetpub\wwwroot\tool\tool128\CrystalReport1.rpt"
        CrystalReportViewer1.DataBind()

Regards
Emre
0
 

Author Comment

by:tentavarious
ID: 11884513
Ok i so i need to execute some export method using CrystalReportViewer1.some export method.  I used the intellisence and i cant find any export method.  What am i missing?
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11884528
ok let me open my visual studio
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11884560
try CrytsalViewer1.ExportReport
0
 

Author Comment

by:tentavarious
ID: 11884610
Nope i dont have that method, do i have to import another namespace i already have these two
Imports CrystalDecisions.shared
Imports CrystalDecisions.CrystalReports.Engine

Also i tried running the code you gave me above as a test, and it wont go through i keep getting this error

Server Error in '/tool/Tool128' Application.
--------------------------------------------------------------------------------

Missing parameter field current value.

If i delete the fields from the report.  The report shows up, but it doesn't do me any good because i need the parameters.
0
 
LVL 10

Accepted Solution

by:
ebolek earned 300 total points
ID: 11884727
you have to use the report engine object model my friend

use these code this works

for parameetrs
private  CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition SetReportParameters(CrystalDecisions.CrystalReports.Engine.ReportDocument MyReport)
            {
                  //sets the parameter values for main report and sub reports if any
                  CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition ParameterFieldDefinition;
                  CrystalDecisions.Shared.ParameterDiscreteValue  ParameterDiscreteValue;
                  CrystalDecisions.Shared.ParameterValues  ParameterValues;                              
                  int paramcount;
                  paramcount = this.MyParameterValues.Count;
                  ParameterFieldDefinition = null;
                  string ConversionVariable;
                  ConversionVariable = null;                  
                  for (int i = 0; i != paramcount; i++)//have to put paramcount otherwise hard code it .works
                  {
                        ConversionVariable = Convert.ToString(MyReport.DataDefinition.ParameterFields[i].ParameterType);  
                        if (ConversionVariable == "StoreProcedureParameter")       
                        {
                              ParameterFieldDefinition = MyReport.DataDefinition.ParameterFields[i];  
                              ParameterValues = new CrystalDecisions.Shared.ParameterValues();
                              ParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();      
                              ParameterDiscreteValue.Value = this.MyParameterValues[i];      
                              ParameterValues.Add(ParameterDiscreteValue);
                              ParameterFieldDefinition.CurrentValues.Clear();
                              ParameterFieldDefinition.DefaultValues.Clear();  
                              ParameterFieldDefinition.ApplyCurrentValues(ParameterValues);
                        }
                  }
                  return ParameterFieldDefinition;
                                                
            }

for exporting


Myreport.Exportoptions.exportformattype = setdiskfiledestination(myreport, "C:\reportpath");
setformatpdfrftword(myreport, false,1,1);
myreport.export;

myreport is a report document



0
 

Author Comment

by:tentavarious
ID: 11885128
Could you translate to vb.net i am not very good with c sharp, i was planning on using c after i got some more projects done with vb.net, but for now i understand vb.net a lot better.
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11885136
well I dont have much time now. When I have time, i will try.

Regards
Emre
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:tentavarious
ID: 11885332
I'm really confused i used the parameter  code below  and it works fine the dates get placed on the report exactly as they should.  But  the export method does not got through.  Am i correct in saying that the code above should be placed in the export method?

I am using this code to get the parameters on the report and it works, can i leave this procedure alone?  What can i add to my export procedure to make it work.  My report procedure is below the parameters set procedure
'parameter set procedure
 Dim startdate As Date
        Dim enddate As Date
        startdate = Session("StartDate")
        enddate = Session("EndDate")

        Dim paramFields As New ParameterFields

        Dim paramField As New ParameterField
        Dim paramfield2 As New ParameterField
        Dim discreteVal As New ParameterDiscreteValue
        Dim discreteval2 As New ParameterDiscreteValue
        paramField.CurrentValues.Clear()
        paramField.ParameterFieldName = "DateParam"
        discreteVal.Value = startdate
        paramField.CurrentValues.Add(discreteVal)
        paramFields.Add(paramField)

        paramfield2.CurrentValues.Clear()
        paramfield2.ParameterFieldName = "DateParamEnd"
        discreteval2.Value = enddate
        paramfield2.CurrentValues.Add(discreteval2)
        paramFields.Add(paramfield2)
        CrystalReportViewer1.ParameterFieldInfo = paramFields
CrystalReportViewer1.Databind()

'export procedure
 Private Sub ExportPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myexportoptions As CrystalDecisions.Shared.ExportOptions
        Dim mydiskfile As CrystalDecisions.Shared.DiskFileDestinationOptions
        Dim myexportfile As String
        Dim myReport As New CrystalReport1
        myexportfile = "c:\inetpub\wwwroot\tool\tool128\misc" & Session.SessionID.ToString & ".pdf"
        mydiskfile = New CrystalDecisions.shared.DiskFileDestinationOptions
        mydiskfile.DiskFileName = myexportfile
        myexportoptions = myReport.ExportOptions
        With myexportoptions
            .DestinationOptions = mydiskfile
            .ExportDestinationType = .ExportDestinationType.DiskFile
            .ExportFormatType = .ExportFormatType.PortableDocFormat
        End With

        myReport.Export()
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "application/pdf"
        Response.WriteFile(myexportfile)
        Response.Flush()
        Response.Close()
        System.IO.File.Delete(myexportfile)
    End Sub
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11885416
i have explained you this. If you start with viewer, you go eith viewer model. The parameter code that works for you right now, which we fixed, is using object viewer model. However export method you are using is using engine object model. They are diffrent things. Your export method is right so doesnt need to chnage. But parameetr code that works you cant use it with yuor export code. Use the code that I posted for parameters and then use your export code. They are both in engine objectb moel

I know this is frustrating but crystal designed it like this, You have to get a good grip of both object models. Common rule is if you need to chnage lots of thinsg in runtime , use engine model. Viewer is very limited. The things that you want to do with exporting can tbe done with viewer so you cant use the parameter setting code

Use mine and everything will work smooth,

Regards
Emre
0
 

Author Comment

by:tentavarious
ID: 11886702
Ok i get it. If you have time could you please translate to vb.net
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11886708
will try
0
 

Author Comment

by:tentavarious
ID: 11886788
I was able to convert it somewhat, but where can i put in my values and parameter field names below is how i converted.

Private Function SetReportParameters(ByVal MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument) As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
        'sets the parameter values for main report and sub reports if any
        Dim ParameterFieldDefinition As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
        Dim ParameterDiscreteValue As CrystalDecisions.Shared.ParameterDiscreteValue
        Dim ParameterValues As CrystalDecisions.Shared.ParameterValues
        Dim paramcount As Integer
        paramcount = Me.MyParameterValues.Count
        ParameterFieldDefinition = Nothing
        Dim ConversionVariable As String
        ConversionVariable = Nothing
        Dim i As Integer
               For  i = 0 To i  paramcount Step  i + 1
            ConversionVariable = Convert.ToString(MyReport.DataDefinition.ParameterFields(i).ParameterType)
            If ConversionVariable = "StoreProcedureParameter" Then
                ParameterFieldDefinition = MyReport.DataDefinition.ParameterFields(i)
                ParameterValues = New CrystalDecisions.Shared.ParameterValues
                ParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
                ParameterDiscreteValue.Value = Me.MyParameterValues(i)
                ParameterValues.Add(ParameterDiscreteValue)
                ParameterFieldDefinition.CurrentValues.Clear()
                ParameterFieldDefinition.DefaultValues.Clear()
                ParameterFieldDefinition.ApplyCurrentValues(ParameterValues)
            End If
        Next
        Return ParameterFieldDefinition

    End Function
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11886829
i did the parameetr values as a collection
Me.MyParameterValues

you can add your values to this collection and then the method will set those values to the parameetr fields . If you want you can get rid of conversionvariable and if sentence that could be redundant foryour case.

Regards
Emre
0
 

Author Comment

by:tentavarious
ID: 11887028
Could you demonstrate, also where would i call the function from in the page load event?
0
 

Author Comment

by:tentavarious
ID: 11887042
Like i said i have tried using similar code before, but i kept getting errors on the page load saying missing parameters.
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11887080
>>where to call
you can call it in the page load event like you used to do but before you call
crytsaldecisions.engine.reportdocument myreport = new crytsaldecisions.engine.reportdocument;
myreport.load(reportpath);
ArrayList parametervalues = new ArrayList();
parametervalues.Add(value1); //value1
parametervalues.Add(value2); // value2
//Now call the parameetr method make it return crytsaldecisions.engine.reportdocument
//then set it to viewer
CrystalReportViewer1.reportsource =myreport
 

Regards
Emre
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11887088
because you didnt set the parameters correctly.This will do it . trust me it works
0
 
LVL 13

Assisted Solution

by:EwaldL
EwaldL earned 200 total points
ID: 11887660
i have just created a quick sample in vb.net with a date parameter placed on the report. this did the trick for me (mainly based on http://support.businessobjects.com/library/kbase/articles/c2010264.asp)

        Dim crReport As New CrystalReport1
        Dim CrExportOptions As ExportOptions
        Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions
        Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions
        CrDiskFileDestinationOptions.DiskFileName = "c:\test.pdf"
        CrFormatTypeOptions.FirstPageNumber = 1
        CrFormatTypeOptions.LastPageNumber = 1
        CrFormatTypeOptions.UsePageRange = True
        CrExportOptions = crReport.ExportOptions
        With CrExportOptions
            .ExportDestinationType = ExportDestinationType.DiskFile
            .ExportFormatType = ExportFormatType.PortableDocFormat
            .DestinationOptions = CrDiskFileDestinationOptions
            .FormatOptions = CrFormatTypeOptions
        End With

        crReport.SetParameterValue("DataParam", "13/1/2004")
        crReport.Export()
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11887850
SetParametervalue can set the parameters too but what if you dont know the name of the field. If you have 10 parameetrs you have to write it 10 times. It doesnt work in every situation neatly .But definitely you can use it. But the code I posted will do the same for you.

Regards
Emre
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 11889670
would he not have to know the parameter's name anyway,ie to make sure that the date value is passed to the correct parameter? i believe my code has the limitation though that you can only pass a single value to a parameter. yours should allow for multiple values. less code, less flexibility. more code, more flexibility ;-) i thought i post it anyway as tentavarious is new to the .net object model and might prefer things easy for now.
0
 

Author Comment

by:tentavarious
ID: 11892994
Thanks a lot both of you alls i was missing was the crReport.SetParameterValue("DateParam", "13/1/2004") line of code in my export to pdf module.  My old code to set the parameters was worked just fine.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 11898801
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now