Skip to content

Print/export data from crystal report

Sumit Sharma

Asked Sep 27, 2012, 3:55 AM EDT1 answer
Share
LinkedInX
hi,
  I am my data in crystal report.i am using Report Document class and stored procedure(with two input parameters) to bind data in crystal report viewer.
  Parameters of stored procedure can be null.When i display data in report viewer it works but now i want to export/Print data through report viewer print or export button.
and when i click on button it ask for parameters and login information of server.how i solve this problem.

if any one have idea,Please share.......


Thanks in advance.
 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Akkiraju Ivaturi
    0
    //Code for connection Info
    In the button click event add the following code for connection parameters for login information:

    ReportDocument rpt = new ReportDocument();
    ConnectionInfo connectionInfo = new ConnectionInfo();
    TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
    rpt.load("myreport.rpt");

    connectionInfo.ServerName = "your server name";
    connectionInfo.DatabaseName = "your db name";
    connectionInfo.UserId = "your user id";
    connectionInfo.Password = "your password";

    Tables crTables = rpt.Database.Tables;
    foreach(CrystalDecisions.CrystalReports.Engine.Table.CrTable in CrTables)
    {
    crTableLogonInfo = CrTable.LogOnInfo();
    ctTableLogonInfo.ConnectionInfo=crConnectionInfo;
    CrTable.ApplyLogOnInfo(crTableLogonInfo);
    }

    crystalReportViewer1.ReportSource=rpt;
    crystalReportViewer1.Refresh();
    =================================================
    //code for passing parameters
    after you load the crystal report as below:
    rpt.Load(reportPath);
    rpt.setParameterValue("Grouping1",this.ddlgroup1.selectedValue);
    rpt.setParameterValue("Grouping2", this.ddlgroup2.selectedValue);

    then call
    crystalReportViewer1.reportsource = rpt;
    crystalreportviewer1.Refresh();

    Let me know if you have any questions.
    0