Google Analytics

Search This Blog

Friday, October 21, 2011

How To Disable the Parameter Prompt for Crystal Report Using VB.Net

Just sharing, no big deal.

Refer to

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


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


            Cursor.Current = Cursors.WaitCursor

            strReportName = Application.StartupPath & "\Rpt\Report1.rpt"
            CrxReport.Load(strReportName, CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)

            '-1. Refresh ReportDocument object

            '-2. Set ReportDocument object datasource

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

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

            Cursor.Current = Cursors.Default

        Catch ex As Exception
            MsgBox(ex.ToString & vbCrLf & ex.Message & vbCrLf & ex.StackTrace)
        End Try
    End Sub


Anonymous said...

My friend ....YOU ARE GOD !!!!
You saved me!!!

Anonymous said...

Can't thank you enough for sharing this very useful information. I had become very frustated after hours of unsuccessful attempts at removing the annoying parameter prompt dialog box. Your tip has come as a lifesaver to me.
Thanks a ton!!!

Hifni Nazeer said...

Wow! After desperate search I came to your site to solve my problem. Explained in a well organized and lucid manner. Thank You Big Time!

shashi kiran Jillepally said...

hi.. can please explain in C# code and please check the below link i'm getting some problem

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.

Shashi kiran Jillepally

Brandon Teoh said...

Hi Shashi,

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:


1.3)Conversion for LoadReport_1

private void LoadReport_1(Microsoft.VisualBasic.Collection remoteDataCol)


CrystalDecisions.CrystalReports.Engine.ReportDocument CrxReport = new

String strReportName = "";
CrystalDecisions.Shared.ParameterValues paramV;
CrystalDecisions.Shared.ParameterDiscreteValue paramDValue;

Cursor.Current = Cursors.WaitCursor;

strReportName = Application.StartupPath + "\\Rpt\\Report1.rpt";


//-1. Refresh ReportDocument object

//-2. Set ReportDocument object datasource

//-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";

//--- or Method 2 (This also work) ----
//CrxReport.SetParameterValue(0, "ABC Company");
CrxReport.SetParameterValue("MyCompany", paramDValue);

CRViewer.ShowExportButton = true;
CRViewer.ShowPrintButton = true;
CRViewer.ShowGroupTreeButton = true;

Cursor.Current = Cursors.Default;


shashi kiran Jillepally said...

Hi sir thank you so much for the reply but here I'm working on Wesite..

shashi kiran Jillepally said...

Sir please help me to solve the problem in C# web application

Orimaz said...

Thanks bro!

Anonymous said...

I dont know how to thank you. you saved me lot of time. Thank you again