Rdlc report usage method 1-4

Source: Internet
Author: User
Use rdlc reports (1)-(4) FavoritesUse rdlc Report (1)

1. Create a data source

Start vs2005 to create a form project named testproj

 

Select "Add new data source" in the form on the left or click "Add new data source" on the menu ":

 

Select the dialog form and select "Database" to go to "Next ":

 

This data source uses the northwind database provided by sqlserver2000 as an example. Therefore, select sqlserver as the driver in the database. The specific operation depends on the database used (if the connection is Oracle, we recommend that you use the ODP for provided by Oracle. net, address: http://www.oracle.com/technology/global/cn/software/tech/windows/odpnet/index.html ).

 

After selecting the data source, specify the database file and perform a test. If the connection fails, check your software settings.

 

Next, go to the tables and views in the warehouse picking file, open the table, select employees, and click Finish.

 

In the data source window, fields in the selected table and table are displayed for use.

 

You can also view the newly added data file in the resource manager.

 

2. Report Browser

In the new form, add the report browser control:

 

This report browser control integrates the report view and print preview functions, which can be directly output to a printer or to an Excel file or PDF file. for customers who like to view an Excel table, this report control is very good. For more information about the report source and the background information, see related websites.

3. Create a report file

After the report browser control is selected, a small triangle appears in the upper right corner of the control. After you click it, a menu appears, select "design new report" or add a new report file in Solution Explorer:

 

Double-click "table" in "report items" to generate a table in the blank table. We can add data items in the table.

 

This report is designed in a way similar to the report design environment in VB before Ms. In the report designer, I divide a report into five parts: report title area, column title area, data display area, total area, and footer. If the design form of the report is displayed as the header and footer, the form of the report will be clearer:

Select the header and footer:

 

Display result:

 

Now, design the report:

Put a text box in the "Header" area, change the content to "Test Report", center, and zoom in and bold:

 

Select an appropriate column from the data source window and drag it to the "details" table in the report. The data is automatically filled in:

 

 

Save the designed report, return to the report browsing window, and select the designed report for the report Browser:

 

After the report file is selected, the menu is also changed:

 

Specify a data source for the report file and select the Data source:

 

OK. Save the file and run the test file.

4. Preview

Preview The generated report as follows:

 

Is it easy? We can also beautify this simple report. Of course, after I add some beautification functions, the effect may be worse, but this is only for demonstration purposes.

Add a table to the data.

In the report designer, select the area where you want to add a table box.

 

Select the border tool in the toolbar.

 

Select "all borders" as needed ".

 

It looks a little darker than the original Gray Line and can be seen during preview.

Add printing time display

Add a text box that displays the printing time, right-click it, and select attributes:

 

In "file box properties", select the expression generated after "value:

 

Select a time in the expression:

 

Do not forget that there must be a "=" before the expression. If not, manually add one. In order to better meet our habits, we can add a description above, such as the printing time. The expression should be slightly changed: it must start with "=", followed by "printing time: and connect the generated now function with "&" to get what we want.

 

Add serial numbers for rows

For demonstration, I added the sequence number column to the last column of the table.

Add a new column:

 

Enter related values in the column where the serial number is displayed:

 

The expression is followed by nothing, not null. Do not make a mistake.

 

Three functions have been completed. Preview:

 

Is it more beautiful than the original one? At least it is practical.

Use rdlc Report (2) -- use custom dataset <! -- [If! Supportlists] --> 1 <! -- [Endif] --> Create a form

 

<! -- [If! Supportlists] --> 2 <! -- [Endif] --> Create a data source

 

3 <! -- [Endif] --> Create a report

 

The new data report has been generated. Next, set the data source.

<! -- [If! Supportlists] --> 4 <! -- [Endif] --> set the data source automatically generated by the report

Select a report> data source on the toolbar, select the data source to be modified, and rename it, for example, myds.

 

After the modification is complete, confirm to exit this window.

Select a table in the report designer to display properties. Change the dataset name of the table to the name modified above.

 

If a report file contains only one data source, the data value in the table can be directly written as "= Fields! The format of field. value. If it contains multiple data sources, you must specify the value of this field, such as "= (Fields! Field. value, "dataset name "".

<! -- [If! Supportlists] --> 5 <! -- [Endif] --> manually generate a data source

Manually generated datasets must contain the field names designed in the report file. Otherwise, an error occurs.

Generate a dataset:

/// <Summary>

/// Report execution

/// </Summary>

/// <Param name = "sender"> </param>

/// <Param name = "E"> </param>

Private void button#click (Object sender, eventargs E)

{

// Obtain the dataset

String connstring = "Data Source =.; initial catalog = northwind; Integrated Security = true ";

System. Data. sqlclient. sqlconnection conn1 = new system. Data. sqlclient. sqlconnection (connstring );

System. Data. sqlclient. sqlcommand command1 = new system. Data. sqlclient. sqlcommand ("select * from MERs", conn1 );

System. Data. sqlclient. sqldataadapter ada1 = new system. Data. sqlclient. sqldataadapter (command1 );

Dataset c_ds = new dataset ();

Try

{

Conn1.open ();

Ada1.fill (c_ds );

}

Finally

{

Conn1.close ();

Command1.dispose ();

Conn1.dispose ();

}

 

// Specify a report file for the report Browser

This. reportviewer1.localreport. reportembeddedresource = "report. report1.rdlc ";

// Specify the dataset. After the dataset name is a table, it is not a dataset of the dataset type.

This. reportviewer1.localreport. CES. Clear ();

This. reportviewer1.localreport. CES. Add (new Microsoft. Reporting. winforms. reportdatasource ("myds", c_ds.tables [0]);

// Display the report

This. reportviewer1.refreshreport ();

}

Data Display after running:

 

Posted on reading (1189) Comments (8) EDIT add to favorites reference network Abstract category: rdlc report use

Use rdlc report (3) -- input parameters to rdlc report

When a report is used to display the result data to the customer, it is necessary to display certain data in the report in real time, such as the displayed department and printed date. This document only shows how to input one character value to a report. If you have other questions, please discuss them.

1. Create a project testreport, a form, a Textbox, a button, and a reportviewer control.
2. Create a report on reportviewer
3. In the open report designer, select "report Parameters" in "report" on the toolbar, and add a new parameter named "content" and "Data Type" string ". OK.
4. Put a text box on the report designer page, right-click the text box and choose properties. In the "text box properties" window, select the "Edit expression" button (that is, the FX) next to the "value" in the lower part of the "General" tab. In this window, select a parameter in the lower-left box, the parameter set in the previous step is displayed in the lower-right corner. Double-click this parameter. The expected expression = parameters is displayed in the preceding box! Content. value. Save the report. The default report name is report1.rdlc.
5. Double-click the button in the form and write the following code:

This. reportviewer1.localreport. reportembeddedresource = "testreport. report1.rdlc ";
Reportparameter Rp = new reportparameter ("content", this. textbox1.text );
This. reportviewer1.localreport. setparameters (New reportparameter [] {RP });
This. reportviewer1.refreshreport ();

6. Run the project, input data in the text input box, and press the button. Has the data been input into the report?

Posted on long shaoye read (393) Comments (8) EDIT add to favorites reference network Abstract category: rdlc report use

Use rdlc Report (4)-drilling report

This article uses the customers and orders tables in the msserver's built-in northwind library file as examples to create two report files. After querying the customers table data, click customerid Data in this table, the report is transferred to the next report, and the related orders data is displayed, that is, the so-called drilling report in.

1. Open a project, create a new from, and put a button and a reportviewer control.
2. Create a new data source in the project and connect to the northwind database file. The customers and orders tables are displayed.
3. Create a report file and display data in a table. Put the customerid, companyName, and address fields in the MERs table, form a simple report with a header and data, and save the report named mermerreport.
4. Create a report file, which is the same as customerreport. The report is also displayed in a table. Put the orderid, customerid, shipname, and orderdate fields in orders into the table, save the report as orderreport
5. The orderreport data source determines the data of the Data Source Based on the customerreport data in the main report. view the dataset name of the table. I will display it as northwinddataset_orders. You can also create one by yourself, for details, see my rdlc Report (2).
6. Open the customerreport report and set customerid as an index field that can be clicked to transfer it to the next report. Select the customerid field, right-click the field, select the "navigation" tab in the "text box properties" window, and select "Jump to report" in the "HYPERLINK" below. select "orderreport" in the report name, and then press the "parameter... "button, enter a parameter name, such as customerid, and select = Fields! Customerid. value. To distinguish it from other data, you can change the color or underline of this column based on your habits.
7. Set a report parameter in orderreport, which is the same as the name in curtomerreprot to receive parameters passed in the parent table.
8. Create two methods for getting data. One method is to get a dataset from MERs, And the other method is to get a dataset from orders with parameters. These two methods can be implemented by writing a class library or adding them to the vs dataset. For ease of demonstration, I directly used getdata () of MERs and wrote a method of getdatabycustomerid (@ CID) of orders.
9. Write the following code in the from button: Private void button2_click (Object sender, eventargs E)
{
Northwinddataset. customersdatatable dt1 = new northwinddatasettableadapters. customerstableadapter (). getdata ();
This. reportviewer1.localreport. reportembeddedresource = "testreport. customerreport. rdlc ";
This. reportviewer1.localreport. CES. Clear ();
This. reportviewer1.localreport. CES. Add (New reportdatasource ("northwinddataset_customers", dt1 ));
This. reportviewer1.refreshreport ();
}

10. Use the drillthrough event of the report. This event occurs when a drill item is selected and the Code for the next report is as follows: Private void reportviewer1_drillthrough (Object sender, drillthrougheventargs E)
{
Localreport Lp = (localreport) E. Report;
String customerid = LP. getparameters () ["customerid"]. Values [0]. Trim ();

LP. datasources. Clear ();
LP. datasources. Add (New reportdatasource ("northwinddataset_orders ",
New northwinddatasettableadapters. orderstableadapter (). getdatabycustomerid (customerid )));
}

Shipping result:
Run the first report:

Run the second report after drilling:

Posted on long shaoye read (331) Comments (0) EDIT add to favorites reference network Abstract category: rdlc report use

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.