Asp. NET in the use of Crystal Report method _ Practical skills

Source: Internet
Author: User

Some time ago, because in the project to use the report to do the statistics, so I studied the ASP.net Crystal Report use. The execution mode of the Crystal report (i.e. the method of fetching data) can be divided into two kinds:

The first is pull mode: When asked, the Crystal Report connects the database directly to the specified drive and assembles the data.

The other is push mode: developers have to write their own code to connect the data and assemble the dataset, and send it to the report. In some cases, you can use report performance maximization by using Connection Sharing and limiting the size of the record collection.

The report types in Crystal Reports are also divided into two categories:

--strongtyped Report: When you add a report file to a project, it becomes a "strongly-typed" report. In these cases, you will have the power to directly create the report object, which will reduce some code and provide some performance.

--untyped Report: The reports here are not directly included in the project, so they are called ' un-typed ' reports. In this case, you have to use the Crystal Report "Reportdocuemt" object to create an instance, and "Manually" to the use of the report.

Using the Pull mode we will use the following steps to execute the Crystal Report through the pull mode
1. First create the RPT file and use the Crystal Report design interface to set up some necessary data connections.
2. Drag and drop a Crystalreportviewer control to the ASPX page, set its properties to specify the. rpt file that we created in the previous step.
3. Call the DataBind method in code.

Copy Code code as follows:

Reportdocument Reportdoc = new Reportdocument ();
Reportdoc.load (Server.MapPath ("mypulldemo.rpt"));
#region troubleshoot problems with logon errors
TableLogOnInfo logoninfo = new TableLogOnInfo ();//
foreach (CrystalDecisions.CrystalReports.Engine.Table TB in ReportDoc.Database.Tables)
{
Logoninfo = tb. Logoninfo;
LogonInfo.ConnectionInfo.ServerName = "(local)";
LogonInfo.ConnectionInfo.DatabaseName = "MyDatabase";/
LogonInfo.ConnectionInfo.UserID = "sa";
LogonInfo.ConnectionInfo.Password = "sa1234";/
Tb. Applylogoninfo (Logoninfo);
}
#endregion
Crystalreportviewer1.reportsource = Reportdoc;

Crystalreportviewer1.databind ();


Using push mode
We used the following steps to execute the Crystal report using push mode:
1. Design a DataSet
2. Create a. rpt file and assign it to the dataset that was established in the previous step.
3. Drag and drop a Crystalreportviewer control in the ASPX page and connect it to the previous RPT file.
4. Access the database in code and save the data in a dataset
5. Call the DataBind method.

Copy Code code as follows:

Reportdocument Reportdoc = new Reportdocument ();
Reportdoc.load (Server.MapPath ("mypushdemo.rpt"));
String strprovider = "server= (local);D atabase=mydatabase; Uid=sa; Pwd=sa1234 ";
SqlConnection myconn = new SqlConnection (strprovider);
MyConn.Open ();
String Strsel = "SELECT * from Saleofcuntry";
SqlDataAdapter myadapter = new SqlDataAdapter (Strsel,myconn);

--Here the DS has exactly the same dataset structure as the. rpt file to connect to the database, with different names

The purpose of the dataset when creating a. rpt file is to provide a schema for the RPT file.

This populates an instance of the DataSet with DataAdapter as the data source for the report.

Copy Code code as follows:

DataSet ds = new DataSet ();
Myadapter.fill (ds, "Saleofcuntry");
Reportdoc.setdatasource (DS);
Crv.reportsource = Reportdoc;

Crv.databind ();

Related Article

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.