Crystal Report is a report design and development of a powerful tool, powerful, flexible design, in the Crystal Report CD-ROM only provides a fully dynamic example of the report, the use of cumbersome. This paper introduces its simple use method in vc++6.0. Compilation environment: vc++6.0 SP5, Windows Server sp3 (en). One, the import Crystal Report uses the dynamic join library: According to the actual modification file path.
#import "C:\Documents and Settings\Administrator\桌面\cr\craxdrt9.dll" no_namespace
Second, define interface pointer variables
//水晶报表变量
IApplicationPtr m_Application;
IReportPtr m_Report;
//水晶报表控件变量,在对话框中加入该控件
CCrystalReportViewer9 m_CRViewer1;
Third, the concrete realization step
Instantiation of M_application
M_application.createinstance (__uuidof (application));
Get M_report variable
Staff.rpt for a report file created with a wizard, the database uses SQL Server 7.0
M_report =m_application->openreport ("C:\\Documents and settings\\administrator\\ Desktop \\cr\\debug\\staff.rpt");
Set report title
M_report->put_reporttitle (_bstr_t ("Title"));
Setting 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");
To set the Retrieve SQL command
M_report->put_sqlquerystring ((_bstr_t) "SELECT * from person where id< ' 4 ' ORDER by id");
Do not show duplicate fields
M_report->putenableselectdistinctrecords (TRUE);
Set search criteria, use Crystal Report syntax, function with settings retrieve SQL command
M_report->putrecordselectionformula ((_bstr_t) "{person.id}= ' 1");
Set report author
M_report->putreportauthor ("Xiaojin");
Connecting M_report to report controls
M_crviewer1.setreportsource (M_report);
Show Report Tool bar
M_crviewer1.setdisplaytoolbar (TRUE);
Do not display the grouping tree to the left of the report
M_crviewer1.setdisplaygrouptree (FALSE);
Do not display control borders
M_crviewer1.setdisplayborder (FALSE);
Refreshing data
M_crviewer1.refresh ();
Show report Content
M_crviewer1.viewreport ();
In this way, the beautiful Crystal Report is displayed. Exception processing part of the program omitted, please join.