locked
How do you pass parameters to my crystal report from a hyperlink filed? RRS feed

  • Question

  • User763881918 posted

    I am trying to pass parameters to my crystal report from a hyperlink filed.

    On my web page I am using Request QueryString to assign the string to a HiddenFiiled and followed the instructions on this page: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=192 but  my Report is not updating.

    I am using stored procedure with two parameters,@Star, @End this is my Command for it  "MyDB"."dbo"."SP_ABC ";1   '20000115', '20000130'.

    Thank you for your help!

    Thursday, September 5, 2013 8:06 PM

Answers

  • User-37275327 posted

    No still the same error. I added a button to the page and instead of trying to pass the  CR parameters from the text fields on load I am entering them manually, moved the same code from my previous post to run on button click. Followed your suggestion and removed  the reference to the CR control parameters  and still getting the same error. Frown

    Have a try like this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 9, 2013 11:13 PM
  • User763881918 posted

    Thanks a lot  for your help one more time! What solved my problem was setting ReuseParameterValuesOnRefresh="True". !!Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 10, 2013 11:24 PM

All replies

  • User-37275327 posted

    you got any error?? put a debug on where CR bind.

    Thursday, September 5, 2013 11:40 PM
  • User1607087669 posted

    hello

    can please explain  more cleraly 

    1) why you are passing id Querystring i,e is it reuired  to generate report

    2) are you getting some error (can you please post error)

    meanwhile you can debug and findout if their is any error

    Thursday, September 5, 2013 11:57 PM
  • User763881918 posted

    No errors. The parameters I need are passed in my address bar like this: Payments.aspx?begprd=20130401&endprd=20130415. In my code behind I am using lblBegin.text = Request.QueryString("begprd").ToString to get the parameters. What I am trying to do is pass 20130401 and 20130415 as parameters to the report with no success.

    Friday, September 6, 2013 1:11 AM
  • User-37275327 posted

    Passing Querystring does not guarentee showing the report correctly. Post the code behind.

    Friday, September 6, 2013 2:26 AM
  • User763881918 posted

    This is my code on the .aspx page. Just for testing I assigned a DefaultValue to my HiddenFields.

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:SIPConnectionString %>"
    SelectCommand="SP_EXCO" SelectCommandType="StoredProcedure">
    <SelectParameters>
    <asp:ControlParameter ControlID="HiddenField1" DefaultValue="04/15/2013"
    Name="Start" PropertyName="Value" Type="String" />
    <asp:ControlParameter ControlID="HiddenField2" DefaultValue="04/30/2013"
    Name="End" PropertyName="Value" Type="String" />
    </SelectParameters>
    </asp:SqlDataSource>

    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
    <Report FileName="CrystalReport2.rpt">
    <DataSources>
    <CR:DataSourceRef DataSourceID="SqlDataSource1" />
    </DataSources>
    <Parameters>
    <CR:ControlParameter ControlID="HiddenField1" ConvertEmptyStringToNull="False"
    DefaultValue="" Name="@Begin" PropertyName="Value" ReportName="" />
    <CR:ControlParameter ControlID="HiddenField2" ConvertEmptyStringToNull="False"
    DefaultValue="" Name="@End" PropertyName="Value" ReportName="" />
    </Parameters>
    </Report>
    </CR:CrystalReportSource>

    in my  code behind I only have.

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

    lblBegin.Text = Request.QueryString("begprd").ToString

    lblEnd.Text = Request.QueryString("endprd").ToString '--- To display values on the page 

    'HiddenField1.Value = Request.QueryString("begprd") 
    'HiddenField2.Value = Request.QueryString("endprd")

    End Sub

    After assigning HiddenField1" DefaultValue="04/15/2013" and running this I am getting: 

    Error
    Database logon failed.
    Friday, September 6, 2013 11:49 AM
  • User-37275327 posted

    You need to pass database credentials, check following reference

    Reference

    Saturday, September 7, 2013 1:16 AM
  • User763881918 posted

    Thank you for the reference link!  After following the instructions I am getting

    Error

    Missing parameter values.

     this is my aspx page 

    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
    <Report FileName="CrystalReport2.rpt">
    <Parameters>
    <CR:ControlParameter ControlID="TextBox1" ConvertEmptyStringToNull="False"
    DefaultValue="" Name="Start" PropertyName="Text" ReportName="" />
    <CR:ControlParameter ControlID="TextBox2" ConvertEmptyStringToNull="False"
    DefaultValue="" Name="End" PropertyName="Text" ReportName="" />
    </Parameters>
    </Report>
    </CR:CrystalReportSource>

    And this is the code behind

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

            

      

                TextBox1.Text = Request.QueryString("begprd").ToString

                TextBox2.Text = Request.QueryString("endprd").ToString

     

                Dim conInfo As New ConnectionInfo

                With conInfo

                    .ServerName = ".XXX"

                    .DatabaseName = "XXX"

                    .UserID = "XXX"

                    .Password = "XXX"

     

                End With

                Me.CRViewer.ParameterFieldInfo.Clear()

     

                If Me.TextBox1.Text.Trim.Length > 0 And

                    Me.TextBox2.Text.Trim.Length > 0 Then

     

     

                    Me.CRViewer.ReportSource = Server.MapPath("CrystalReport2.rpt")

     

                    Dim ParamFields As ParameterFields = Me.CRViewer.ParameterFieldInfo

     

                    Dim p_Start As New ParameterField

                    Dim p_End As New ParameterField

     

                    p_Start.Name = "Start"

                    p_End.Name = "End"

     

                    Dim p_Start_Value As New ParameterDiscreteValue

                    Dim p_End_Value As New ParameterDiscreteValue

     

                    p_Start_Value.Value = Me.TextBox1.Text

                    p_End_Value.Value = Me.TextBox2.Text

     

                    p_Start.CurrentValues.Add(p_Start_Value)

                    p_End.CurrentValues.Add(p_End_Value)

                    ParamFields.Add(p_Start)

                    ParamFields.Add(p_End)

                Else

                    Me.CRViewer.ReportSource = Server.MapPath("CrystalReport2.rpt")

                End If

                For Each cnInfo As TableLogOnInfo In Me.CRViewer.LogOnInfo

                    cnInfo.ConnectionInfo = conInfo

                Next

                Me.CRViewer.RefreshReport()

            End Sub

        End Class

     Thank you for your help one more time!

    Saturday, September 7, 2013 10:29 PM
  • User-37275327 posted

    I dont think you need following code since you are declaring para fields from the code behind.

    <Parameters>
    <CR:ControlParameter ControlID="TextBox1" ConvertEmptyStringToNull="False" 
    DefaultValue="" Name="Start" PropertyName="Text" ReportName="" />
    <CR:ControlParameter ControlID="TextBox2" ConvertEmptyStringToNull="False" 
    DefaultValue="" Name="End" PropertyName="Text" ReportName="" />
    </Parameters>



    Saturday, September 7, 2013 11:20 PM
  • User763881918 posted

    No still the same error. I added a button to the page and instead of trying to pass the  CR parameters from the text fields on load I am entering them manually, moved the same code from my previous post to run on button click. Followed your suggestion and removed  the reference to the CR control parameters  and still getting the same error. Frown

    Monday, September 9, 2013 8:19 PM
  • User-37275327 posted

    No still the same error. I added a button to the page and instead of trying to pass the  CR parameters from the text fields on load I am entering them manually, moved the same code from my previous post to run on button click. Followed your suggestion and removed  the reference to the CR control parameters  and still getting the same error. Frown

    Have a try like this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 9, 2013 11:13 PM
  • User763881918 posted

    Thanks a lot  for your help one more time! What solved my problem was setting ReuseParameterValuesOnRefresh="True". !!Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 10, 2013 11:24 PM