Usage of Crystal Reports in vc6.0
Author: [fengyunshuang Jue]
1. Import the dynamic link library used by the crystal Report: Modify the file path according to the actual situation.
# Import "D: // crcraxdrt9.dll" no_namespace
Ii. Define interface pointer Variables
// Crystal report variable
Iapplicationptr m_application;
Ireportptr m_report;
// Crystal report control variable. Add the control to the dialog box.
Ccrystalreportviewer9 m_crviewer1;
Iii. Implementation steps
// Instantiate m_application
M_application.createinstance (_ uuidof (Application ));
// Obtain the m_report variable
// Staff. rpt is a report file created through the Wizard. The database uses SQL Server 7.0
M_report = m_application-> openreport ("C: documents and settingsadministrator desktop crdebustaff. rpt ");
// Set the report title
M_report-> put_reporttitle (_ bstr_t ("title "));
// Set database connection Variables
// Database Server (local), Database Name staff, user name SA, password SA
M_report-> database-> tables-> item [1]-> setlogoninfo ("(local)", "staff", "sa", "sa ");
// Set the search SQL command
M_report-> put_sqlquerystring (_ bstr_t) "select * From person where ID <'4' order by ID ");
// Do not display duplicate fields
M_report-> putenableselectdistinctrecords (true );
// Set the search conditions and use the crystal report syntax. The function is the same as setting the search SQL command.
M_report-> putrecordselectionformula (_ bstr_t) "{person. ID} = '1 '");
// Set report author
M_report-> putreportauthor ("Xiaojin ");
// Connect m_report to the report Control
M_crviewer1.setreportsource (m_report );
// Display the report Toolbar
M_crviewer1.setdisplaytoolbar (true );
// The group tree on the left of the report is not displayed.
M_crviewer1.setdisplaygrouptree (false );
// Do not display the widget border
M_crviewer1.setdisplayborder (false );
// Refresh data
M_crviewer1.refresh ();
// Display the Report Content
M_crviewer1.viewreport ();
In this way, the beautiful crystal report is displayed. The exception handling part of the program is omitted. Please add it on your own.