Applications in Microsoft reportviewer (Microsoft Report) Projects

Source: Internet
Author: User

Abstract:

Applications in Microsoft reportviewer (Microsoft Report) Projects

1. Create a dataset
[Add]-[new item]-[dataset]-[orderreport. XSD]
After creation, right-click and choose add> dataadapter. The Configuration Wizard is displayed, and the corresponding data connection is created.
(Omitted)-[next step]
When an SQL statement is entered, paste the SQL statement into the content (view supported) and click [Query Builder ]-
Query the corresponding result-[next]-[complete]
Dataset created
Ii. Create a report
[Add]-[new item]-[report]-[orderreport. rdlc]
In the toolbar above vs, choose Report> data source> report data source> drop-down list.
[Orderreport _ *******]-[add to report]-[OK]
In the toolbox, drag table to the design view, and a table is displayed. Click any part of the table.
In the gray area, right-click the upper left corner of the table and choose Properties]
In the displayed table Properties window, select the data source you just added from the dataset name drop-down list.
[Orderreport _ *******]-[OK]
You can add [columns] In the area above the gray area, merge [columns], and add
Enter the field you want to add
The "details" area in the table is the data you want to read from the database. Select a unit in the "details" line.
Grid-right-click and choose expression. The expression window is displayed.
Fields, datasets, and functions are available in category. For example, category-select field-rightmost.
[Field] shows the field to be queried in the data just now-double-click [***** (ordercode )]
-[OK]: repeats the operation to complete the expressions of all fields.
Report created
3. Create a page
Process omitted
In the toolbox-Report-drag microsoftreportviewer to the page, in the corresponding event
Insert the following code

Protected void btntosearch_click (Object sender, eventargs E)
{
Datatable dt = new datatable ();
Dt = bllo. getorderreport ();
Microsoft. Reporting. webforms. reportdatasource DS = new
Reportdatasource ("orderreport _ *******", DT );
This. reportviewer1.localreport. reportpath =
@ "Report \ orderreport. rdlc ";
Reportviewer1.localreport. displayname = "statistical table ";
Reportviewer1.localreport. CES. Clear ();
Reportviewer1.localreport. CES. Add (DS );
Reportviewer1.databind ();
}
Complete

 

Bytes -----------------------------------------------------------------------------------------------------------------

Reportviewer reports create reports with parameter stored procedures and PASS Parameters for rdlc

First, let's look at a table structure.
Create Table Test
(
PID varchar (100 ),
Pname varchiar (100 ),
Pqty int,
Pprice money
)
Create a stored procedure
Create procedure proctest
@ Condition varchar (1000)
As
Declare @ SQL varchar (8000)
Set @ SQL = 'select PID, pname, pqty from Test'
If @ condition <>''
Set @ SQL = @ SQL + @ Condition
Exec (@ SQL)
Here, we can see that the msdn and online examples use direct select statements with parameter stored procedures, but many times they need to be constructed
SQL statements for query, so here I mainly talk about how to use exec to construct the stored procedure of SQL statements.
Create an ASP. NET webapplication and add a new one to the app_code directory (if not, right-click Add ASP. NET folder to create this directory ).
Item, select dataset, enter the dataset name, and click OK.
Right-click Add in the window and select tableadapter. The tableadapter Connection Wizard dialog box is displayed. Connect to the database (this process is omitted) and select use
Existing stored procedrues (an existing stored procedure), click Next, select proctest, and click Finish directly. A tableadapter is created.
.
If the stored procedure is directly select PID, pname, pqty from test, the tableadapter will directly treat PID, pname, and pqty
The column is displayed, but exec is used. Therefore, you must manually add the PID, pname, and pqty In the right-click and choose create column. After adding them, save the disk, and then
Create a report file. After the report file is created, the newly created tableadapter is displayed on the left side of the report window. Drag the PID, pname, and pqty columns
In the report window, save the layout.
Open the default. aspx file (create one by yourself). Drag the reportview control in the toolbox to the window and select the newly created report.
File, then drag a textbox and a button, double-click the button to open the code window and fill in the code
View plaincopy to clipboardprint?
Protected void button#click (Object sender, eventargs E)
{
String condition = "";
If (textbox1.text. Trim ()! = "")
{
String condition = "pid = '" + textbox1.text. Trim () + "'";
}

// Clear original data source parameters
Objectperformance1.selectparameters. Clear ();
// Add data source parameters
Objectperformance1.selectparameters. Add ("condition", condition );
// Let reportview reload the data source
Reportviewer1.localreport. Refresh ();
}
Protected void button#click (Object sender, eventargs E)
{
String condition = "";
If (textbox1.text. Trim ()! = "")
{
String condition = "pid = '" + textbox1.text. Trim () + "'";
}
// Clear original data source parameters
Objectperformance1.selectparameters. Clear ();
// Add data source parameters
Objectperformance1.selectparameters. Add ("condition", condition );
// Let reportview reload the data source
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.