Click here to Skip to main content
15,888,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help, We have a strange problem in report view.

We have some reports, when we try to preview for a particular record, the first time report come with complet data of detail / footer section (without filtered with our assigned parameeter). But if we run the same report second time onwards until closing the project the report comming with filtered detail / footer data, which is the correct and expecting result.

but we could not understand why the first time report come with wrong data (unfiltered).

There is no any error recording for this particular problem.

<pre lang="vb">   
Dim cryRpt As New ReportDocument
        Dim RepPath As String = GetReportAppPath()
        If RepPath = "NoPath" Then
            MessageBox.Show("Please set the report location", "Invalid Report Location!", MessageBoxButtons.OK)
            Me.Close()
        Else
            Try
                cryRpt.Load(RepPath & ReportName & ".rpt")
                Me.Text = ReportName & System.DateTime.Now.Date
                Dim _ServerName As String = IP
                Dim _DatabaseName As String = DB
                Dim _UserID As String = DBID
                Dim _Password As String = DBPW
                Dim Logon As New TableLogOnInfo
                Dim Tbl As Table
                For Each Tbl In cryRpt.Database.Tables
                    Logon = Tbl.LogOnInfo
                    Logon.ConnectionInfo.ServerName = _ServerName
                    Logon.ConnectionInfo.DatabaseName = _DatabaseName
                    Logon.ConnectionInfo.Password = _Password
                    Logon.ConnectionInfo.UserID = _UserID
                    Logon.ConnectionInfo.IntegratedSecurity = False
                    Tbl.ApplyLogOnInfo(Logon)
                Next
                Dim Subreport As ReportDocument
                For Each Subreport In cryRpt.Subreports
                    For Each Tbl In Subreport.Database.Tables
                        Logon = Tbl.LogOnInfo
                        Logon.ConnectionInfo.ServerName = _ServerName
                        Logon.ConnectionInfo.UserID = _UserID
                        Logon.ConnectionInfo.Password = _Password
                        Logon.ConnectionInfo.IntegratedSecurity = False
                        Tbl.ApplyLogOnInfo(Logon)
                    Next
                Next
                Dim val As String = Para1
                Dim paramField As New ParameterField
                Dim paramDiscreteValue As New ParameterDiscreteValue
                Dim paramFields As New ParameterFields
                paramField.Name = "para"
                paramDiscreteValue.Value = val
                paramField.CurrentValues.Add(paramDiscreteValue)
                paramFields.Add(paramField)
                Select Case ReportName
                    Case "rptSupRFQ_Normal", "rptSupRFQ_Principle", "rptSupRFQ_Direct", "rptQuotation_preview"
                        Dim paramField1 As New ParameterField
                        Dim paramDiscreteValue1 As New ParameterDiscreteValue
                        paramField1.Name = "ItmDes"
                        paramDiscreteValue1.Value = frmNewSearch.chkVenderDesc.Checked
                        paramField1.CurrentValues.Add(paramDiscreteValue1)
                        paramFields.Add(paramField1)
                    Case "rptCusDelv_preview", "rptCusInv_preview"
                        Dim paramField1 As New ParameterField
                        Dim paramDiscreteValue1 As New ParameterDiscreteValue
                        paramField1.Name = "type"
                        paramDiscreteValue1.Value = frmNewSearch.chkOriginal.Checked
                        paramField1.CurrentValues.Add(paramDiscreteValue1)
                        paramFields.Add(paramField1)
 
                End Select
                CrystalReportViewer1.ParameterFieldInfo = paramFields
                CrystalReportViewer1.ReportSource = cryRpt
                CrystalReportViewer1.Refresh()
            Catch ex As Exception
                el.WriteToErrorLog(ex.Message)
                Me.Close()
            End Try
        End If
</pre>
Posted
Updated 4-Oct-13 23:14pm
v2

Add your parameter in the crystal report and then pass the value from your code.

After adding parameter in report add the bellow code

paramField1.SetParameterValue("ItmDes", paramDiscreteValue1)

Thanks
Nitish
 
Share this answer
 
Comments
exfosys 5-Oct-13 6:48am    
Thanks Nitish,

We will check this and come back to you..
thatraja 5-Oct-13 6:49am    
Well spotted, 5!
exfosys 5-Oct-13 6:58am    
Nitish,

parameter is already in the crystal report and it is pass through code also.

but the above code line is not recognized. the message as below

'SetParameterValue' is not a member of 'CrystalDecisions.Shared.ParameterField'.
NitSam 5-Oct-13 7:07am    
yes exfosys. its member of CrystalDecisions.CrystalReports.Engine.ReportDocument and you have to use cryRpt.SetParameterValue("ItmDes", paramDiscreteValue1) (according to your code). means use SetParameterValue() with ReportsDocument.

what i have posted earlier that was wrong sorry for inconvenience.
exfosys 5-Oct-13 7:17am    
Now the code line is recognized but problem still there...
Verify Save Data With Report[^] option is unchecked.

EDIT
------------
Agree with 2nd solution, the order is wrong. You have to pass value after adding that.

VB.NET Crystal Reports String parameter[^]
 
Share this answer
 
v2
Comments
exfosys 5-Oct-13 6:40am    
Thanks for your reply,,

But this proporty is not selected in our report.
thatraja 5-Oct-13 6:47am    
check my updated answer
exfosys 5-Oct-13 7:09am    
Dim paramField1 As New ParameterField
Dim paramDiscreteValue1 As New ParameterDiscreteValue
paramField1.Name = "ItmDes"
paramDiscreteValue1.Value = frmNewSearch.chkVenderDesc.Checked
paramField1.CurrentValues.Add(paramDiscreteValue1)
paramFields.Add(paramField1)
paramField1.SetParameterValue("ItmDes", paramDiscreteValue1)

but in the last line of th code 'SetParameterValue' is not recognized
exfosys 5-Oct-13 7:44am    
Now the code line is recognized but problem still there...

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