How to set DataSource for RDLC Report using Report Viewer in C#
By Tan Lee Published on Feb 16, 2024 1.33K
To set up a DataSource for a local report using the ReportViewer control in a C# Windows Forms application, you can follow these steps.
To play the demo, You should create a new dataset, then add a new table to your dataset.
This process involves creating a local report, configuring the DataSource, and binding it to the ReportViewer control.
To set data source for the local report at run time you can write your code as shown below
ReportData data = ReportData();//ReportData is a dataset //If your report needs parameters, they need to be set ReportParameter[] parameters = new ReportParameter[...]; ReportDataSource reportDataSource = new ReportDataSource(); //Must match the DataSource in the RDLC reportDataSource.Name = "ReportData"; reportDataSource.Value = data.Customer; //Your table in ReportData // Add any parameters to the collection reportViewer1.LocalReport.SetParameters(parameters); reportViewer1.LocalReport.DataSources.Add(reportDataSource); reportViewer1.RefreshReport();
You need to create a ReportDataSource, then set data to the Value property - e.g. DataTable and IEnumerables are supported sources.
- Primitive types in C#
- How to set permissions for a directory in C#
- How to Convert Int to Byte Array in C#
- How to Convert string list to int list in C#
- How to convert timestamp to date in C#
- How to Get all files in a folder in C#
- How to use Channel as an async queue in C#
- Case sensitivity in JSON deserialization
Categories
Popular Posts
RuangAdmin Template
Nov 13, 2024
11 Things You Didn't Know About Cloudflare
Dec 19, 2024
AdminKit Bootstrap 5 HTML5 UI Kits Template
Nov 17, 2024
Modular Admin Template
Nov 14, 2024