References for rdlc reports

Source: Internet
Author: User

This example is mainly implemented.
A. Simple presentation of report1.rdlc associated with reportviewer
B. Presentation of report1.rdlc with report Parameters
C. Program-generated dataset filling report
D. Call the stored procedure to generate a dataset filling report
============
Simple presentation
============
1. OpenVS2005, File-> New-> select the language type for the website (C #)
2. design the generated default. aspx in this solution
3. SetToolbox-Pull the reportviewer under data to the design interface of default. aspx.
4. When you select reportviewer1 with the mouse, you can see the small triangle icon in the upper right corner.
5. Click the triangle with the mouse to expand the reportviewer task shortcut menu
6. Because no reports have been prepared for this project, select to design a new report.
7. Click design new report to display the report report1.rdlc design interface.
8. The project does not have a website data source.
Add a new data source.
(If the "website data source" interface is not displayed, you can click the report design interface,
"Data", "Report", and other options appear in the top menu.
You can select "display data source" under the "data" menu ")
9. Click "Add new data source". The "tableadapter Configuration Wizard" appears"
10. Select data connection (for example, to connect to the local northwind database) and next
11. Select whether to save the connection string to the application configuration file. Next
12. Select the command type. Click Cancel to exit the wizard.
13. Save all
14. Select "server resource manager" under the View menu ",
You can see the data connection just created,
You can see tables, views, stored procedures, and functions in the northwind database.
15. Find and open the dataset1.xsd dataset in the app_code folder under the solution tree.
16. You can see that the open Dataset Designer is empty. In this case, you can set "server resource manager"
Northwind tables or stored procedures under the drop-in Dataset Designer
(For example, the stored procedures of the orders table and sales by year are pulled)
17. Save all
18. Double-click report1.rdlc to open the report design page.
Design the current reportToolboxInReport itemTable drop-in report design page
19. Select "display data source" under the "data" menu ",
You can see the two tables orders and sales by year in dataset1 under the website data source.
20. Select any field (such as orderid and customerid) under orders)
Go to "details" of the report1.rdlc design table for report display.
21. Save all
22. Return to the design interface of default. aspx and bind the report to reportviewer1.
Select reportviewer1 to display the designed report1.rdlc.
23. Save all. Press F5 or Ctrl F5 to run the command to view the initial effect.

==============================================
Next, add a report parameter for report1.rdlc.
==============================================

24. Return to the report report1.rdlc design page.
Click "report Parameters" under the report menu"
25. In the report parameters setting box, add a report parameter for relevant settings and click OK to save
(If the parameter name is rptparaa, the type is string)
26. Pull a text boxReport itemGo to the report1.rdlc design interface to display the report title
27. Right-click the text box and select "expression" from the pop-up menu ",
Enter the "Edit expression" dialog box
28. In the "Edit expression" dialog box, select a parameter,
Double-click the rptparaa you just set to make the value of the text box = parameters! Rptparaa. Value
29. Save the modification to report1.rdlc
30. Because the text box of the new report1.rdlc report requires the input of report parameter values
Therefore, when reportviewer1 presents report1.rdlc
Edit default. aspx. CS
31. Add reference in default. aspx. CS
Using Microsoft. Reporting. webforms;
Add the following code to page_load:

Reportparameter rptparaa = new reportparameter ("rptparaa", "test report Parameters ");
Reportviewer1.localreport. setparameters (New reportparameter [] {rptparaa });

32. Save and run the command to view the effect

========================================================== =
Next, you need to customize the report materials to be presented.
That is, by designing Dataset
Bind and present the report with the required data
========================================================== =

33. Set visible of reportviewer1 to false
34. Add a button button1 to the design interface of default. aspx.
The click event of this button is used to access the database and populate the dataset data.
Bind to the data of reportviewer1
35. add reference to default. aspx. CS
Using system. Data. sqlclient;
Using Microsoft. Reporting. webforms;

The code example in button#click is as follows:

Sqlconnection myconn = new sqlconnection ("Data Source = 192.168.0.36; initial catalog = northwind; user id = sa; Password = sa ");
Sqldataadapter myda = new sqldataadapter ("select top 5 * from orders", myconn );
Dataset myds = new dataset ();
Myconn. open ();
Myda. Fill (myds );
Myconn. Close ();

Reportviewer1.visible = true;

Reportparameter rptparaa = new reportparameter ("rptparaa", "test report Parameters ");
Reportviewer1.localreport. setparameters (New reportparameter [] {rptparaa });

Reportdatasource RDS = new reportdatasource ("datasetemediorders", myds. Tables [0]);
Reportviewer1.localreport. CES. Clear ();
Reportviewer1.localreport. CES. Add (RDS );
Reportviewer1.localreport. Refresh ();

Note: reportdatasource RDS = new reportdatasource ("datasetemediorders", myds. Tables [0]);
"Datasetemediorders" is used with the front-end HTML Program

<Rsweb: reportviewer id = "reportviewer1" runat = "server" font-names = "verdana" font-size = "8pt" Height = "400px" visible = "false" width = "400px">
<Localreport reportpath = "report1.rdlc">
<Datasources>
& Nbsp; <rsweb: reportdatasource performanceid = "objectperformance1" name = "datasetemediorders"/>
</Datasources>
</Localreport>
</Rsweb: reportviewer>
The name = "datasetemediorders" of <datasources> In is consistent.

You can customize the SQL statement when filling the dataset to obtain the required data for report presentation.
Note that the report associated with report1.rdlc is in reportviewer1, so the structure in tables [0] of dataset is
Must contain the fields presented by report1.rdlc. Therefore, the SQL statement here is select top 5 * from orders
36. Save running click button1 for report Presentation

========================================================== ========
If the data to be presented in the report comes from the Stored Procedure
Then, when loading the dataset, make the data from the stored procedure.
========================================================== ========

37. Right-click the project to add a new project, select a report, and add report2.rdlc to the project,
Set the data source to the stored procedure sales by year
Similarly, add "table" to the design interface of report2.rdlc"Report item
The fields in the sales by year table under dataset1 under the website data source
Pull inReport item"Table" is displayed in detailed data
38. Add a new page named default2.aspx to the project like default. aspx
Add a button and reportviewer1 to default2.aspx.
Set reportviewer1 as report2.rdlc.
Set visible of reportviewer1 to false
Double-click a button to write its Click Event
Set default2.aspx as the project start page
39. Add reference in default2.aspx. CS
Using system. Data. sqlclient;
Using Microsoft. Reporting. webforms;
40. The code example of the button#click event is as follows:

Protected void button#click (Object sender, eventargs E)
{
Sqlconnection myconn = new sqlconnection ("Data Source = 192.168.0.36; initial catalog = northwind; user id = sa; Password = sa ");
Sqldataadapter myda = new sqldataadapter ("sales by year", myconn );
Myda. selectcommand. Parameters. addwithvalue ("@ beginning_date", "1997-10-10 ");
Myda. selectcommand. Parameters. addwithvalue ("@ ending_date", "2000-10-10 ");
Myda. selectcommand. commandtype = commandtype. storedprocedure;
Dataset myds = new dataset ();
Myconn. open ();
Myda. Fill (myds );
Myconn. Close ();

Reportviewer1.visible = true;

Reportdatasource RDS = new reportdatasource ("datasetasksales_by_year", myds. Tables [0]);
Reportviewer1.localreport. CES. Clear ();
Reportviewer1.localreport. CES. Add (RDS );

Reportviewer1.localreport. Refresh ();
}

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.