I used the PULL mode method uploaded on the Internet to load the report. When printing, an error occurs: a communication error occurs. Print will stop
The data source I use is the stored procedure of SQL Server.
Solution:
Bind the crystal report to page_init.
Private void page_init (Object sender, eventargs E)
{
Cr_bind ();
}
Private void buttonimg_click (Object sender, system. Web. UI. imageclickeventargs E)
{
Cr_bind ();
}
Public void cr_bind ()
{
// Crystalreport. rpt is the name of the crystal report file. crystalreportsource1 is the object of the crystal report data source added to the page from the toolbox.
Crystalreportsource1.reportdocument. Load (server. mappath ("crystalreport1.rpt "));
// This method must be used in setdatabaselogon PULL mode to set logon information. Parameters 1: User Name; parameter 2: password; parameter 3: Server; parameter 4: Database Name
Crystalreportsource1.reportdocument. setdatabaselogon ("sa", "sa", @ ".", "iccard ");
// Transmit parameters to the crystal report. Parameter 1: Parameter Name, parameter 2: parameter value;
Crystalreportsource1.reportdocument. setparametervalue ("areaname_text", "this is a test report ");
// Crystalreportsource1.reportdocument. setparametervalue ("shopname_text", "1 ");
// Bind the crystal report data source.
Crystalreportsource1.databind ();
// Crystalreportviewer1 is the crystal report browser.
Crystalreportviewer1.reportsource = crystalreportsource1;
Crystalreportviewer1.databind ();
}