Add parameters and connection strings to the Crystal Report

Source: Internet
Author: User

On the ASPX page, set connectionstring and parameters to input a report, and use crystalreportviewer to use exporttohttpresponse to output a PDF file for download.

Private void exportpdfreport ()

{

If (file. exists (mappath ("~ /Reports/dropshipinvoice. rpt ")))
{

ReportDocument rptdropshipinvoice = new reportdocument ();

// Obtain the report location and Load
Rptdropshipinvoice. Load (mappath ("~ /Reports/dropshipinvoice. rpt "));
Rptdropshipinvoice. reportoptions. enablesavedatawithreport = false;

// Initialize database connection information. Set the connection string
VaR connectionstring =
New sqlconnectionstringbuilder (dbutils. actualconnectionstring );

// Set the connection string for each report or subreport in the report.
Foreach (iconnectioninfo connection in rptdropshipinvoice. cececonnections)
{
If (connectionstring. integratedsecurity)
{
Connection. setconnection (connectionstring. datasource, connectionstring. initialcatalog,
Connectionstring. integratedsecurity );
}
Else
{
Connection. setconnection (connectionstring. datasource, connectionstring. initialcatalog,
Connectionstring. userid, connectionstring. Password );
}
}

// Input parameters to the report

Rptdropshipinvoice. setparametervalue ("begindate", calandarshipday. selecteddate );
Rptdropshipinvoice. setparametervalue ("enddate", calandarshipday. selecteddate. adddays (1 ));
Rptdropshipinvoice. setparametervalue ("customeruserid", currentloginuser. userid. tostring ());
Rptdropshipinvoice. setparametervalue ("mainsiteapplicationid", systemconfiguration. mainsiteapplicationid. tostring ());

// Export a report

Exportreport (rptdropshipinvoice, "dropshipinvoice" + calandarshipday. selecteddate. tostring ("yyyymmdd"), exportformattype. portabledocformat );
}

// Exportreport method. Export the data in the report template on the ASPX page and generate a PDF file.

Private void exportreport (corresponding parameter)

{

Httpcontext. Current. response. Buffer = false;

// Clear the response content and headers
Httpcontext. Current. response. clearcontent ();
Httpcontext. Current. response. clearheaders ();

Rptdropshipinvoice. exporttohttpresponse (formattype, httpcontext. Current. Response, true, strexportfilename );
Httpcontext. Current. response. Flush ();
Httpcontext. Current. response. End ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.