Initial use of Crystal Reports (integrated with vs. net2003, version = 9.1.5000.0)
After installation, You need to register the registration number: 6707437608 password: aap5gks?gde100ds
To use a crystal report in The. aspx File
1. First create a file webform1.aspx and drag the component crystalreportviewer to generate code.
2. Create the file crystalreport1.rpt in the same folder of the project? In the field Resource Manager database Field "add Database", use oledb to connect to select the data table you want to display in the report (with a wizard)
3. The main code in webform1.aspx. CS is as follows:
Protected crystaldecisions. Web. crystalreportviewer crystalreportviewer1;
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
Tablelogoninfo logoninfo = new tablelogoninfo ();
ReportDocument orpt = new reportdocument ();
String rptdir = "f :\\ BBS \ test \ crystal \ crystalreport1.rpt"; // the absolute path of the crystalreport1.rpt File
Orpt. Load (rptdir );
// Set the logoninfo parameter. If not set here? During compilation, the "Login Failed" error is the easiest!
Logoninfo. connectioninfo. servername = "server name ";
Logoninfo. connectioninfo. databasename = "Database Name ";
Logoninfo. connectioninfo. userid = "username ";
Logoninfo. connectioninfo. Password = "password ";
Orpt. database. Tables [0]. applylogoninfo (logoninfo );
// Establish a connection between the. rpt file and the crystalreportviewer File
Crystalreportviewer1.reportsource = orpt;
}
4. // generate a PDF document and add it to the above Code
Exportoptions crexportoptions = new exportoptions ();
Diskfiledestinationoptions crdiskfiledestinationoptions = new diskfiledestinationoptions ();
Crdiskfiledestinationoptions. diskfilename = "F: \ BBS \ test \ crystal \ crystalreport1.pdf ";
Crexportoptions = orpt. exportoptions;
Crexportoptions. destinationoptions = crdiskfiledestinationoptions;
Crexportoptions. exportdestinationtype = exportdestinationtype. diskfile;
Crexportoptions. exportformattype = exportformattype. portabledocformat;
Orpt. Export ();
Orpt. Close ();
5. // read the exported report content and upload it to the client? Continue to add the following code
Response. clearcontent ();
Response. clearheaders ();
Response. contenttype = "application/pdf ";
Response. writefile ("F: \ BBS \ test \ crystal \ crystalreport1.pdf ");
Response. Flush ();
Response. Close ();?
The above is my usage summary. please correct me if there is anything wrong or can be improved !!!