Getting started with Crystal Reports under vs2010

Source: Internet
Author: User

The usage of the Crystal Report in vs2010 is recorded as follows:

1. First, vs2010 no longer comes with the crystal report control. You need to download and install the corresponding crystal report control: crforvs_13_0. This control is easy to install. You can select the default settings.

2. After installation, add a new item in vs2010 and select "reporting". The options of "crystalreports" are shown below. This is the crystal report file.

3. Create a New crystalreports file. vs2010 will display a wizard for generating a crystal Report Template. You can generate the report file as instructed by the wizard step by step. Here I select the standard mode.

4. according to the database connection prompt in the Wizard, I chose an Oracle server connection to connect the Crystal Report to the database. I only need to enter the service name, user, and password as required, the crystal report template is connected to Oracle.

5. select the expected table or view and select the corresponding fields (I skipped the grouping and Filtering Field settings), and then select the report style, the crystal report automatically generates a default template for you.

 

You can further optimize the style on this template, including adding, merging, and other advanced operations.

6. Now, the template is created and the code is written.

Create a webform, select report design in the toolbox, and drag and drop a crystalreportviewer control to the page. This is the Web control of the crystal report, with it, you can easily implement many complex functions.

7. You can control the display effect of the control by controlling its properties as needed.

For example:

Hasprintbutton = "false" // do not display the print button

Hascrystallogo = "false" // do not display the Crystal Report logo

Hasdrilldownabs = "false" // The Download button is not displayed.

Hasdrillupbutton = "false" // the upload button is not displayed.

Hasgotopagebutton = "false" // The Skip button is not displayed.

Toolpanelview = "NONE" // do not display the toolbar

Hastogglegrouptreebutton = "false" // the crystal report tree button is not displayed.

8. How can we make this crystal report run on the page? The following is the relevant code.

First, it should be noted that the crystal report has the same PULL mode and push mode as many report controls. The so-called PULL mode is to specify the data source in the template, and directly obtain the data through the template and display it to the control mode, which is also the mode I am using. The push mode organizes data sources in the program and pushes the data to the Crystal Report Template. The mode is displayed on the control. It is an advanced application and is more advanced and flexible, of course, you also need to write more code.

Here we will mainly use the simple and easy-to-use PULL mode.

First, initialize the Crystal Report class and load the required template.

1 // find the crystal report template. My crystal report is saved in the webreport folder under the root directory of the web system, 2 string masterplatename = "test. RPT "; 3 string reportpath = server. mappath (request. applicationpath + "/webreport/" + masterplatename); 4 reportdocument myreport = new reportdocument (); 5 myreport. load (reportpath );

Next, you need to specify a connection string for the database connection of the template to prevent the crystal report from connecting to the database.

// Define the database connection information of the Crystal Report connectioninfo = new connectioninfo (); // obtain the webconfig connection string soraclecon = system. configuration. configurationmanager. appsettings ["connectionstring"]. trimend (';'); // process the data source. The user and password string [] listoraclecon = new string [3]; string [] listoraclecontemp1 = soraclecon. split (';'); For (INT I = 0; I <listoraclecontemp1.length; I ++) {string [] listoraclecontemp2 = listoraclecontemp1 [I]. split ('='); listoraclecon. setvalue (listoraclecontemp2 [1], I);} // database name or database service connectioninfo. databasename = listoraclecon [0]; // connectioninfo. userid = listoraclecon [1]; // connectioninfo. password = listoraclecon [2]; // database address. You do not need to set // connectioninfo for the Oracle database. servername = "localhost"; // pass the database information to the report setdblogonforreport (connectioninfo, myreport );
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument){     Tables tables = reportDocument.Database.Tables;      foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)     {         TableLogOnInfo tableLogonInfo = table.LogOnInfo;         tableLogonInfo.ConnectionInfo = connectionInfo;         table.ApplyLogOnInfo(tableLogonInfo);      }} 

Finally, assign the Crystal Report object to the Page Template

// Assign the template object to the report front-end Rendering Control crystalreportviewer1 crystalreportviewer. reportsource = myreport;

After compilation, you can see the effect on the page, which is very convenient and quick.

At last, record it. In the push mode, you need to connect to the database through code, generate a dataset, then pass it to the Crystal Report class, and assign it to the template. So that you can learn it later.

DataSet ds = new DataSet();ReportDocument myReport = new ReportDocument();myReport.SetDataSource(ds); CrystalReportViewer.ReportSource = myReport;

 

 

 

 

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.