C# 2005 - How do I pass parameters from TextBoxes in a windowsform to a Crystal Report IX ?

Hello everybody,

Greetings from Brazil! I need to pass parameters directly from TextBoxes in a windowsform to a Crystal Report IX through code, avoiding that ugly Crystal Report parameter prompt.

Can anybody please send me some sample code or let me know where I can find a tutorial I have searched the Internet for days but did not find anything.

Thanks a lot for your time and help! I really appreciate it.

All the best,

JC :)




Answer this question

C# 2005 - How do I pass parameters from TextBoxes in a windowsform to a Crystal Report IX ?

  • bhavu

    Hello mewdied. Thanks for the sample code, but, is that it What would come before and after that Please don't overestimate me. I'm a newbie :)

  • bkallich

    The code needed is:

    myRepotDocument.SetParameterValue("MyParameterName", MyParameterValue);


  • longwood12345

    Hi Charly. Thanks a lot for the link, but I had already looked at that tutorial. It didn't do it for me. :)

  • donnie100

    you need to create a reportdocument object first.

    ReportDocument myReport = new ReportDocument();
    myReport.Load(@"C:\MyReports\myReport.rpt");

    Then set any parameters using the line I gave earlier.
    Then view the report, or export, or whatever you want to do.

    If you are creating the report as part of the object you can declare it using the filename without the extension. If you have a report called CrystalReport1.rpt then do the following:

    CrystalReport1 myReport = new CrystalReport1();

    This is equivalent to the two lines at the top


  • Khass

    Hello mewdied,

    It's all beginning to make sense to me now. I'm gonna set 3 parameters in the report itself and define the formulas for them:

    prmClient
    prmStartDate
    prmEndDate

    I will pass the parameters to the report from 3 textboxes in a windows form:

    ClientTextBox
    StartDateTextBox
    EndDateTextBox

    Are the following lines of code correct then

    private void ShowReportButton_Click(object sender, EventArgs e)
    {
    ReportDocument myReport = new ReportDocument();
    myReport.Load(@"C:\MyReports\myReport.rpt");
    myRepotDocument.SetParameterValue("prmCliente", ClientTextBox.Text);
    myRepotDocument.SetParameterValue("prmStartDate", StartDateTextBox.Text);
    myRepotDocument.SetParameterValue("prmEndDate", EndDateTextBox.Text);
    }

    Thanks a lot for all your help! :)



  • B.Huard

    Looks good to me. The only thing you may need to watch out for is with the date parameters. If you make them as type date in the report, you need to pass them a date type, or make sure the string is formatted correctly.
  • SGriffiths

    Try this tutorial - http://msdn2.microsoft.com/en-us/library/ms227697.aspx


  • C# 2005 - How do I pass parameters from TextBoxes in a windowsform to a Crystal Report IX ?