Use rdlc Report (2)-use custom Dataset

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

/// </Summary>

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

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

Private VoidButton#click (ObjectSender, eventargs E)

{

// retrieve a dataset

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

System. Data. sqlclient. sqlconnection conn1= NewSystem. Data. sqlclient. sqlconnection (connstring );

System. Data. sqlclient. sqlcommand command1= NewSystem. Data. sqlclient. sqlcommand ("Select * from MERs", Conn1 );

System. Data. sqlclient. sqldataadapter ada1= NewSystem. Data. sqlclient. sqldataadapter (command1 );

Dataset c_ds= NewDataset ();

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 a dataset. The dataset name is followed by a table, datasets not of the dataset type

This . reportviewer1.localreport. datasources. clear ();

This . reportviewer1.localreport. datasources. add ( New Microsoft. reporting. winforms. reportdatasource ( " myds " , c_ds.tables [ 0 ]);

//Show reports

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.