Related search suggestions provided.
What is Microsoft Report Viewer?
Microsoft Report Viewer is a Windows Forms control that allows developers to display reports in their .NET applications. It is part of the Microsoft Reporting Services and can be used to display reports created using Reporting Services, Report Builder, or other reporting tools.
Key Features of Microsoft Report Viewer
How to Use Microsoft Report Viewer
Benefits of Using Microsoft Report Viewer
Common Use Cases for Microsoft Report Viewer microsoft report viewer
Code Example
Here is an example of how to use the Report Viewer control in a Windows Forms application:
using System;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
namespace ReportViewerExample
public partial class Form1 : Form
public Form1()
InitializeComponent();
private void Form1_Load(object sender, EventArgs e)
// Create a new report viewer
ReportViewer reportViewer = new ReportViewer();
// Set the report source
reportViewer.LocalReport.ReportEmbeddedResource = "Report1.rdlc";
// Add the report viewer to the form
this.Controls.Add(reportViewer);
// Refresh the report
reportViewer.RefreshReport();
This example creates a new Report Viewer control, sets the report source to a report file (.rdlc), and adds the control to a Windows Forms application. Related search suggestions provided
byte[] bytes = reportViewer.LocalReport.Render("PDF");
File.WriteAllBytes("report.pdf", bytes);
The visual studio designer can handle some binding, but for dynamic data, code-behind is preferred.
using System;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms; // Namespace for the control
using System.Data;
namespace MyReportingApp
public partial class Form1 : Form
public Form1()
InitializeComponent();
private void Form1_Load(object sender, EventArgs e)
// 1. Clear any previous data sources
reportViewer1.LocalReport.DataSources.Clear();
// 2. Define the path to the RDLC file
reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
// 3. Fetch your data (Simulated here with a DataTable)
DataTable myData = GetInvoiceData();
// 4. Create a ReportDataSource
// The name "DataSet1" must match the name you set inside the RDLC designer
ReportDataSource rds = new ReportDataSource("DataSet1", myData);
// 5. Add the data source to the viewer
reportViewer1.LocalReport.DataSources.Add(rds);
// 6. Refresh the report to render
this.reportViewer1.RefreshReport();
private DataTable GetInvoiceData()
// Simulate database retrieval
DataTable dt = new DataTable();
dt.Columns.Add("CustomerName", typeof(string));
dt.Columns.Add("Amount", typeof(decimal));
dt.Rows.Add("John Doe", 500.00m);
dt.Rows.Add("Jane Smith", 1200.50m);
return dt;
Be aware of these constraints before committing to the control:
Crucial Note: As of 2023, Microsoft has shifted the Report Viewer to an open-source model (GitHub) for the modern .NET versions. The classic WinForms control is now part of the Microsoft.ReportingServices.ReportViewerControl.WinForms NuGet package and requires a Windows operating system (it does not run on Linux or macOS). How to Use Microsoft Report Viewer
Add a Subreport item in the RDLC designer, then handle the SubreportProcessing event:
reportViewer1.LocalReport.SubreportProcessing += (s, e) =>
e.DataSources.Add(new ReportDataSource("OrderDataset", GetOrders(e.Parameters["CustomerID"].Values[0])));
;
Let’s walk through two common scenarios: a WinForms application using Local Mode (RDLC) and an ASP.NET Core application (via WebForms compatibility).