Solved

assign parameters in crystal report VB.net

Posted on 2004-08-03
19
1,250 Views
Last Modified: 2012-08-13
how do i use date parameters in crystal report VB.net ? i am new to this so i need step by step instructions .
kindly assist
0
Comment
Question by:rohini_pb29
  • 9
  • 8
19 Comments
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
To pass a date value to a date parameter:

1) Add a report to your project.

2) Add a date parameter to the report. Call it "DateParam".

3) Add the following lines of code to the top of the code page to import the relevant namespaces:


'Import namespaces in general declarations
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

4) Add the following code to pass a date parameter to a Report at runtime using VB.net

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)

5) Pass the report object to the WinForm or WebForm viewer and run the application

--------------------------------------------------------------------------------

[ Above copied from: http://support.businessobjects.com/library/kbase/articles/c2010247.asp ]

HTH

frodoman
0
 

Author Comment

by:rohini_pb29
Comment Utility
in the selection expert i have given the formula as
  {A.NAM}='Ro' and
{B.DATE} >={?DateParam}

and under page_load function after connection to the database code , i have pasted the code given by u.
here is the error i got ...

Server Error in '/test1' Application.
--------------------------------------------------------------------------------

Missing parameter field current value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: CrystalDecisions.CrystalReports.Engine.ParameterFieldCurrentValueException: Missing parameter field current value.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[ParameterFieldCurrentValueException: Missing parameter field current value.]
   .F(String       , EngineExceptionErrorID 
) +574
   CrystalDecisions.CrystalReports.Engine.FormatEngine.internalSetReportInfo(RequestContext reqContext) +1293
   CrystalDecisions.CrystalReports.Engine.FormatEngine.internalGetViewContext(ReportPageRequestContext reqContext, * viewContext) +217
   CrystalDecisions.CrystalReports.Engine.FormatEngine.GetPage(PageRequestContext reqContext) +280
   CrystalDecisions.ReportSource.LocalReportSourceBase.GetPage(PageRequestContext pageReqContext) +189
   CrystalDecisions.Web.ReportAgent.u(Boolean N) +164
   CrystalDecisions.Web.CrystalReportViewer.OnPreRender(EventArgs e) +108
   System.Web.UI.Control.PreRenderRecursiveInternal() +62
   System.Web.UI.Control.PreRenderRecursiveInternal() +125
   System.Web.UI.Control.PreRenderRecursiveInternal() +125
   System.Web.UI.Page.ProcessRequestMain() +1489

 ------------------------------------
there is another line of code in the page_load fn. given as

CrystalReportViewer1.ReportSource = crpt
CrystalReportViewer1.ReportSource = Server.MapPath("all_benj.rpt")

crystalreport1 in the report name generated by VS.net and i have added all_benj. rpt which has date  parameter.
should this b crystalreport1.rpt or all_benj? i tried both but the error  remained the same.

any clue ?
Thanx,
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Can you paste the code that you put in (copied from here) - I suspect something minor prior to this line:

   ' Add parameter value
   crParameterValues = crParameterFieldDefinition.CurrentValues

frodoman
0
 

Author Comment

by:rohini_pb29
Comment Utility
this is webform1.aspx.vb

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared


Public Class WebForm1
    Inherits System.Web.UI.Page
    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


#Region " Web Form Designer Generated Code "
    Dim crpt As CrystalReport1
    Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
    Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        crpt = New CrystalReport1

        For Each myTable In crpt.Database.Tables
            myLogin = myTable.LogOnInfo
            myLogin.ConnectionInfo.Password = "abcdef"
            myLogin.ConnectionInfo.UserID = "usedId"
            myTable.ApplyLogOnInfo(myLogin)
        Next

        CrystalReportViewer1.ReportSource = crpt

        CrystalReportViewer1.ReportSource = Server.MapPath("all_benj.rpt")

        Dim crReport As New CrystalReport1

       
        'Set Date Parameter

        'Set discrete value
        crParameterDiscreteValue.Value = CDate("8/04/2004")

        '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)

    End Sub

End Class

thanx,
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
At the beginning of your page load section you have:  

   crpt = New CrystalReport1

And then you apply login info and set the viewer to use crpt.

Then you have:

   Dim crReport As New CrystalReport1

And from this point on you use crReport to set your parameter values.


So as far as I can tell it looks like you're doing half the work to the crpt object and half the work to the crReport object.  Use one or the other throughout and I think you'll be okay.

frodoman
0
 

Author Comment

by:rohini_pb29
Comment Utility
i did as  u said.


Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared


Public Class WebForm1
    Inherits System.Web.UI.Page
    ' 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


#Region " Web Form Designer Generated Code "
    Dim crpt As CrystalReport1
    Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
    Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        crpt = New CrystalReport1
        ' Dim crReport As New CrystalReport1
        For Each myTable In crpt.Database.Tables
            myLogin = myTable.LogOnInfo
            myLogin.ConnectionInfo.Password = "abcdef"
            myLogin.ConnectionInfo.UserID = "usedId"
            myTable.ApplyLogOnInfo(myLogin)
        Next

        CrystalReportViewer1.ReportSource = crpt

        CrystalReportViewer1.ReportSource = Server.MapPath("all_benj.rpt")

        'Set Date Parameter

        'Set discrete value
        crParameterDiscreteValue.Value = CDate("8/04/2004")

        'Access first parameter field definition
        crParameterFieldDefinitions = crpt.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)

    End Sub

End Class


but again :(
here is the error

Server Error in '/test1' Application.
--------------------------------------------------------------------------------

Missing parameter field current value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: CrystalDecisions.CrystalReports.Engine.ParameterFieldCurrentValueException: Missing parameter field current value.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[ParameterFieldCurrentValueException: Missing parameter field current value.]
   .F(String       , EngineExceptionErrorID 
) +574
   CrystalDecisions.CrystalReports.Engine.FormatEngine.internalSetReportInfo(RequestContext reqContext) +1293
   CrystalDecisions.CrystalReports.Engine.FormatEngine.internalGetViewContext(ReportPageRequestContext reqContext, * viewContext) +217
   CrystalDecisions.CrystalReports.Engine.FormatEngine.GetPage(PageRequestContext reqContext) +280
   CrystalDecisions.ReportSource.LocalReportSourceBase.GetPage(PageRequestContext pageReqContext) +189
   CrystalDecisions.Web.ReportAgent.u(Boolean N) +164
   CrystalDecisions.Web.CrystalReportViewer.OnPreRender(EventArgs e) +108
   System.Web.UI.Control.PreRenderRecursiveInternal() +62
   System.Web.UI.Control.PreRenderRecursiveInternal() +125
   System.Web.UI.Control.PreRenderRecursiveInternal() +125
   System.Web.UI.Page.ProcessRequestMain() +1489

 

hope there is a solution soon .... i am left with only today...
thanx,
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Is your CR parameter a Date or a DateTime?  If it's DateTime you'll need to include a time in your CDate() function.
0
 

Author Comment

by:rohini_pb29
Comment Utility
i am sorry if this sounds like a silly qiestion...
i gave
crParameterDiscreteValue.Value = CDate("8/04/2004 00:00:00")

but i got error:
Missing parameter field current value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: CrystalDecisions.CrystalReports.Engine.ParameterFieldCurrentValueException: Missing parameter field current value.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

as server error.


but i had one question.
in database the date is in the form of  date time.
but in the report (with out .net  just run locally) it just takes date.like 08/03/2004
in parameter i changed it to date time , (it was date before when i used to run the same report locally without.net, it works fine.)


making parameter as date time i tried crParameterDiscreteValue.Value = CDate("8/04/2004 00:00:00")
and
crParameterDiscreteValue.Value = CDate("8/04/2004") both  gave the same error


thanx,
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:rohini_pb29
Comment Utility
could there be any problem with the permissions given for the browser ???

i could open a normal report with out having a parameter in the browser though....

thanx,
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Do you have subreports in this report?  I'm thinking that this error may be because there's a parameter in a subreport that isn't being set.  If this is possible look at subreports and make sure any parameters are linked to main report or you'll have to pass in those parameters as well.

If no subreports then I'll keep digging.  I don't think this has anything to do w/ the browser.

frodoman
0
 

Author Comment

by:rohini_pb29
Comment Utility
yes there is a subreport.

i am sorry for not giving the full detail.

in subreport also there is same date but in my report it goes this way

{A.ACC_NUM} = {?Pm-A.ACC_NUM}
and
{B.DATE} >= {?Pm-?Start Date}


and in the main report it is this way as i told u before

{A.NAM}='Ro' and
{B.DATE} >={?DateParam}

should i just rename start Date as DateParam ?

thanx, u r giving me hopes!! and i am sorry again...
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Good news - I think we're on the right track...

Okay, in your main report you have {?DateParam} and this is the value that must be passed to the subreport, right?  Is {?StartDate} the parameter in your subreport?  If so then you should be linked to {?StartDate} not to {?pm-StartDate}...

Best way to do this (in my humble opinion) is in your subreport create a parameter named "SubDateParam" (I always append a 'sub' prefix to the same parameter name - helps me keep it straight).  Rt-click the subreport and 'change links'.  In the "Container Report Fields to Link To" box you should have {?DateParam} and in the "Subreport Parameter field to use" you should have {?SubDateParam}.

Let me know if that does it.

frodoman
0
 

Author Comment

by:rohini_pb29
Comment Utility
no it dint work,

i just made a quick report which has no subreport
in the main report select expert it has a simple formula
{B.DATE} >={?DateParam}

it works fine with out .net environment.
so i added this report as myname.rpt

dint work !!!

gave server error as :

Server Error in '/test1' Application.
--------------------------------------------------------------------------------

Missing parameter field current value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: CrystalDecisions.CrystalReports.Engine.ParameterFieldCurrentValueException: Missing parameter field current value.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[ParameterFieldCurrentValueException: Missing parameter field current value.]
   .F(String       , EngineExceptionErrorID 
) +574
   CrystalDecisions.CrystalReports.Engine.FormatEngine.internalSetReportInfo(RequestContext reqContext) +1293
   CrystalDecisions.CrystalReports.Engine.FormatEngine.internalGetViewContext(ReportPageRequestContext reqContext, * viewContext) +217
   CrystalDecisions.CrystalReports.Engine.FormatEngine.GetPage(PageRequestContext reqContext) +280
   CrystalDecisions.ReportSource.LocalReportSourceBase.GetPage(PageRequestContext pageReqContext) +189
   CrystalDecisions.Web.ReportAgent.u(Boolean N) +164
   CrystalDecisions.Web.CrystalReportViewer.OnPreRender(EventArgs e) +108
   System.Web.UI.Control.PreRenderRecursiveInternal() +62
   System.Web.UI.Control.PreRenderRecursiveInternal() +125
   System.Web.UI.Control.PreRenderRecursiveInternal() +125
   System.Web.UI.Page.ProcessRequestMain() +1489
------------------------------------------------

i  want to know y this is not working so i took the previous report which is complex and has subreport.
i expected this simple report to work.

i have 2 question...

CDate("8/04/2004") '  is different from CDate ("2004,08,01") ?
i dont think so but asking just to clarify.

DateParam parameter field i gave it as Date Time .

and

CrystalReportViewer1.ReportSource = Server.MapPath("CrystalReport1.rpt")

should it be myname.rpt or CrystalReport1.rpt  and what is the  difference ?

and what do u think is the problem ??
now how ever long it takes i need to find out the problem.. so plz help me...
0
 

Author Comment

by:rohini_pb29
Comment Utility
???
 i am trying and trying and tryin...
no use all the time i see the  same error :(

u tooo ????
0
 

Author Comment

by:rohini_pb29
Comment Utility
hi,
any luck from your side ?


0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Sorry rohini - I'm in the middle of something here at work and haven't been able to look at this again.  I'll try to get to it tonight if I can. - frodoman
0
 
LVL 42

Accepted Solution

by:
frodoman earned 250 total points
Comment Utility
Sorry again rohini,  I've looked but I can't find anything about this error that isn't related to a missing / null parameter value.

When you tried w/out subreport, where there other parameters on the main report that you didn't specify a value for?

I will also say that date are the worst parameters to pass because the conversion of date formats between systems doesn't always work well.  Perhaps you should try getting a report working with a numeric parameter first - then you know your code is solid and if it fails when you switch to a date param you know it's because of date format and you can track that down.

frodoman
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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 …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

16 Experts available now in Live!

Get 1:1 Help Now