In. before net2005, SQL Server reporting services provided a language called report Definition Language (RDL. in net 2005, Microsoft provides a report designer for this type, and provides the ability to use this type of report in winform and webform. Microsoft sets the report suffix rdlc. RDL is still the abbreviation of report definition language. What does C mean? C stands for client-side processing, which highlights its client processing capability.
The ease-of-use and customization of such reports give us reason to discard crystal report. Let's take a look at its powerful functions:
1. Easy-to-use controls, especially table controls, facilitate the arrangement of fields on reports.
2. Flexible customization. XML is used to describe everything related to a report.
3. Highly programmable. In your project, you do not even need a report file.CodeYou can generate, preview, and print reports.
4. Support for drillthrough data Drilling
5. The exported Excel file is in perfect format, and no other reports are comparable in this respect, and you do not need to install Excel
The following is a simple report on group statistics:
-
- Open Vs and create a new winformProgram, Add a new item, select report
- The report needs to be bound to data, so the next step is to add the data source. You can add "add data source" to link to a table or view through the database connection string, but you do not need to use the database to provide dataset. The "configure data adapter" interface is canceled. Right-click dataset and add a "table"
-
- Drag a table from the "toolbar" on the report design page to the report. By default, this table has three rows: Header, detail, and footer. As the name suggests, header is the header, detail is the content to be displayed, and footer is the end of the table. You can perform some statistics here. Design the corresponding format of the table, add the table edge width, and center the font. Bind the corresponding data fields, drag the newly created dataset field directly, and add the report function "= rownumber (nothing)" to the sequence number column )", many functions can be used in rdlc. Right-click a cell and choose "property". The function dialog box appears when "FX" is clicked in "value. Add the statistical line, open the report, and type "= sum (fields!" in the income column of the footer row! Income. Value) "is the sum. Add group statistics, click the table, right-click "inert group" on the left, and insert a group. The settings are as follows:
-
- Finally, the report design is as follows:
-
- Create a fomr form, drag the "reportviewer" control from the toolbar, click the upper right corner of the control, and select the report you just created.
- Then we manually write the data binding code in the background, as shown below:
Using System; Using System. Collections. Generic;Using System. componentmodel; Using System. Data; Using System. drawing; Using System. LINQ; Using System. text; Using System. Windows. forms; Using Microsoft. Reporting. winforms; Namespace Reportview { Public Partial Class Frmreportview: FORM { Public Frmreportview () {initializecomponent ();} Private Void Frmreportview_load ( Object Sender, eventargs e) {datatable dt = getdata (); // Datasetfirst_datatablefirst must be the same as the data source name configured for the table in the rdlc report. Reportdatasource RDS = New Reportdatasource (" Datasetfirst_datatablefirst ", DT); reportviewer1.localreport. CES. Clear (); reportviewer1.localreport. CES. Add (RDS); reportviewer1.refreshreport ();} Private Datatable getdata () {datatable dt = New Datatable (" Dataname "); DT. Columns. Add ( New Datacolumn (" Name ", Typeof ( String ); DT. Columns. Add ( New Datacolumn (" Income ", Typeof ( Decimal ); DT. Columns. Add ( New Datacolumn ("Dept ", Typeof ( String ); Datarow DR = DT. newrow (); Dr [" Name "] =" Zhang San "; Dr [" Income "] = 3300.00 m; Dr [" Dept "] =" Personnel "; DT. Rows. Add (DR); DR = DT. newrow (); Dr [" Name "] =" Li Si "; Dr [" Income "] = 3500.00 m; Dr [" Dept "] =" Logistics "; DT. Rows. Add (DR); DR = DT. newrow (); Dr [" Name "] =" XJ "; Dr [" Income "] = 7500.00 m; Dr [" Dept "] =" Technology "; DT. Rows. Add (DR); DR = DT. newrow (); Dr [" Name "] =" CSC "; Dr [" Income "] = 8500.00 m; Dr ["Dept "] =" Technology "; DT. Rows. Add (DR ); Return DT ;}}}
-
- You can see the following results when running the command: