Just sharing, no big deal.
Refer to
http://msdn.microsoft.com/en-us/library/ms227086%28v=vs.90%29.aspx
This applies to MS .NET programming using Visual Studio 2008 SP1.
Three things to take note.
1. ) Do not invoke CrystalReportViewer.RefreshReport Method
This method will refresh the data for the report currently displayed in the CrystalReportViewer control. The report will prompt for parameters or logon info is necessary.
So, this method is not needed unless the same CrystalDecisions.CrystalReports.Engine.ReportDocument object is reused.
2.) Procedures (Must follow this order)
2.1. Refresh ReportDocument object
2.2. Set ReportDocument object datasource
2.3. Set ReportDocument object as CrystalReportViewer.ReportSource
2.4. Set parameters to ReportDocument
3.) Two ways of setting parameters at step 2.4
3.1) Using a combination of
CrystalDecisions.Shared.ParameterField.CurrentValues
CrystalDecisions.Shared.ParameterField.HasCurrentValue
3.2) Using CrystalReports.Engine.ReportDocument.SetParameterValue
Sample Codes:
Refer to
http://msdn.microsoft.com/en-us/library/ms227086%28v=vs.90%29.aspx
This applies to MS .NET programming using Visual Studio 2008 SP1.
Three things to take note.
1. ) Do not invoke CrystalReportViewer.RefreshReport Method
This method will refresh the data for the report currently displayed in the CrystalReportViewer control. The report will prompt for parameters or logon info is necessary.
So, this method is not needed unless the same CrystalDecisions.CrystalReports.Engine.ReportDocument object is reused.
2.) Procedures (Must follow this order)
2.1. Refresh ReportDocument object
2.2. Set ReportDocument object datasource
2.3. Set ReportDocument object as CrystalReportViewer.ReportSource
2.4. Set parameters to ReportDocument
3.) Two ways of setting parameters at step 2.4
3.1) Using a combination of
CrystalDecisions.Shared.ParameterField.CurrentValues
CrystalDecisions.Shared.ParameterField.HasCurrentValue
3.2) Using CrystalReports.Engine.ReportDocument.SetParameterValue
Sample Codes:
Public Sub LoadReport_1(Optional ByVal remoteDataCol As Collection = Nothing) Dim CrxReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument Dim strReportName As String Dim paramV As CrystalDecisions.Shared.ParameterValues Dim paramDValue As CrystalDecisions.Shared.ParameterDiscreteValue Try Cursor.Current = Cursors.WaitCursor strReportName = Application.StartupPath & "\Rpt\Report1.rpt" CrxReport.Load(strReportName, CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault) '-1. Refresh ReportDocument object CrxReport.Refresh() '-2. Set ReportDocument object datasource CrxReport.SetDataSource(remoteDataCol) '-3. Set ReportDocument object as CrystalReportViewer.ReportSource CRViewer.ReportSource = CrxReport '-4. Set parameters to ReportDocument ---- paramV = New CrystalDecisions.Shared.ParameterValues paramDValue = New CrystalDecisions.Shared.ParameterDiscreteValue paramDValue.Value = "ABC Company" paramV.Add(paramDValue) '--- Method 1 (This works) ---- CrxReport.ParameterFields.Item("MyCompany").CurrentValues = paramV CrxReport.ParameterFields.Item("MyCompany").HasCurrentValue = True '--- or Method 2 (This also work) ---- 'CrxReport.SetParameterValue(0, "ABC Company") 'CrxReport.SetParameterValue("MyCompany", paramDValue) CRViewer.ShowExportButton = True CRViewer.ShowPrintButton = True CRViewer.ShowGroupTreeButton = True CRViewer.Zoom(100) Cursor.Current = Cursors.Default Catch ex As Exception MsgBox(ex.ToString & vbCrLf & ex.Message & vbCrLf & ex.StackTrace) End Try End Sub
Comments
You saved me!!!
Thanks a ton!!!
http://dotnetmentors.com/reporting/crystal-report-with-stored-procedure-parameter-and-visual-studio.aspx
The above the article(link) is about using store procedure in crystal reports with parameter, it is working fine for the first post back but the problem is when I am selecting Ddl agian and clicking Getreport button for next time it is asking for the parameters again(Enter values(popup),please help me to solve this problem and if possible improve the code for multiple parameters.
Thanks,
Shashi kiran Jillepally
I do not have the time to look thoroughly into the URL which you referenced there.
However, with a quick glimpse, it looks that the codes provided under '5. Display CustomerOrder on ASP.NET ASPX page' didn't attempt to 'silence' the parameter prompt.
Hence, if you are talking about direct conversion of this sample into C#, here it is:
1.1)Assuming that CRViewer is a type of CrystalDecisions.Windows.Forms.CrystalReportViewer
1.2)Need to include references for:
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.Shared
CrystalDecisions.Windows.Forms
1.3)Conversion for LoadReport_1
private void LoadReport_1(Microsoft.VisualBasic.Collection remoteDataCol)
{
CrystalDecisions.CrystalReports.Engine.ReportDocument CrxReport = new
CrystalDecisions.CrystalReports.Engine.ReportDocument();
String strReportName = "";
CrystalDecisions.Shared.ParameterValues paramV;
CrystalDecisions.Shared.ParameterDiscreteValue paramDValue;
Cursor.Current = Cursors.WaitCursor;
strReportName = Application.StartupPath + "\\Rpt\\Report1.rpt";
CrxReport.Load(strReportName,
CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault);
//-1. Refresh ReportDocument object
CrxReport.Refresh();
//-2. Set ReportDocument object datasource
CrxReport.SetDataSource(remoteDataCol);
//-3. Set ReportDocument object as CrystalReportViewer.ReportSource
CRViewer.ReportSource = CrxReport;
//-4. Set parameters to ReportDocument ----
paramV = new CrystalDecisions.Shared.ParameterValues();
paramDValue = new CrystalDecisions.Shared.ParameterDiscreteValue();
paramDValue.Value = "ABC Company";
paramV.Add(paramDValue);
//--- or Method 2 (This also work) ----
//CrxReport.SetParameterValue(0, "ABC Company");
CrxReport.SetParameterValue("MyCompany", paramDValue);
CRViewer.ShowExportButton = true;
CRViewer.ShowPrintButton = true;
CRViewer.ShowGroupTreeButton = true;
CRViewer.Zoom(100);
Cursor.Current = Cursors.Default;
}