Report service rdlc (2)

Source: Internet
Author: User
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:

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.