Use SQL statements to directly generate dataset as the report data source!

Source: Internet
Author: User
Experience in using Crystal Reports 2-use SQL statements to directly generate dataset as the report data source!

The last time I made the method of using oledb to connect to the database directly in the rpt file, but it was not very flexible. This time I used SQL statements to directly generate dataset as the report data source (that is, the push mode ), in this way, you can accept the parameter. Of course, I have not studied the function of setting parameters in reports in detail.

I. Table association is not used in SQL statements (simple query statements)
Design a dataset
1) Right-click solution browser and choose "add"> "Add new item"> "dataset"
2) drag and drop the "stores" table (in the pubs database) from "SQL Server" in "server resource manager)
3) A structure chart of the stores table is displayed in the dataset. The XSD file only contains a structure chart, but no data is contained in it.

Create a. rpt file crystalreport1.rpt and specify it to the dataset created in the previous step.
4) use the method described above to create this file. The only difference is that you can use a dataset instead of directly connecting to the previous data.
5) after creating the. rpt file, right-click "details" --> "Add/delete database"
6) in the "Database Expert" window, expand "project data" (instead of the previous oledb), expand "ADO. Net dataset" -- "dataset1", and select "stores" table.
7) add the "stores" table to the "selected table" and click "OK"
8) create a webform1.aspx and drag a crystal report viewer control.

9) webform1.aspx. CS
ReportDocument orpt = new reportdocument ();
String rptdir = "F: // bbs // test // crystal // crystalreport1.rpt ";
Orpt. Load (rptdir );

... // Obtain dataset based on SQL statements.

Orpt. setdatasource (DS );
Crystalreportviewer1.reportsource = orpt;

// Note that the logoninfo parameter cannot be set in Push mode.

10) run it! It should be okay.
Also sent to the Crystal Report 10 download: http:// SC .fixdown.com/fixdown/download.asp? Id = 14867 & free = SX-down

Posted on zsww read (1624) Comments (7) EDIT favorites

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.