Hi Prasunjeet,
Please refer below smaple.
For populating RDLC Report in Windows Application refer below article.
Namespaces
C#
using System.Data.SqlClient;
using Microsoft.Reporting.WinForms;
using System.Drawing.Printing;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
Imports System.Drawing.Printing
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
Customers dsCustomers = GetData();
ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(datasource);
this.reportViewer1.RefreshReport();
}
private Customers GetData()
{
string constr = @"Data Source=.\Sql2005;Initial Catalog=Northwind;Integrated Security = true";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 20 * FROM customers"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (Customers dsCustomers = new Customers())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}
}
private void Print(object sender, EventArgs e)
{
this.reportViewer1.PrintDialog();
PageSetupDialog setupDlg = new PageSetupDialog();
PrintDocument printDoc = new PrintDocument();
setupDlg.Document = printDoc;
setupDlg.AllowMargins = false;
setupDlg.AllowOrientation = false;
setupDlg.AllowPaper = false;
setupDlg.AllowPrinter = false;
setupDlg.Reset();
printDoc.DefaultPageSettings.PaperSize = new PaperSize("A5", 850, 1400);
}
VB.Net
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim dsCustomers As Customers = GetData()
Dim datasource As New ReportDataSource("Customers", dsCustomers.Tables(0))
Me.ReportViewer1.LocalReport.DataSources.Clear()
Me.ReportViewer1.LocalReport.DataSources.Add(datasource)
Me.ReportViewer1.RefreshReport()
End Sub
Private Function GetData() As Customers
Dim constr As String = "Data Source=.\Sql2005;Initial Catalog=Northwind;Integrated Security = true"
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT TOP 20 * FROM customers")
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dsCustomers As New Customers()
sda.Fill(dsCustomers, "DataTable1")
Return dsCustomers
End Using
End Using
End Using
End Using
End Function
Private Sub Print(sender As System.Object, e As System.EventArgs) Handles btnPrint.Click
Me.ReportViewer1.PrintDialog()
Dim setupDlg As PageSetupDialog = New PageSetupDialog()
Dim printDoc As PrintDocument = New PrintDocument()
setupDlg.Document = printDoc
setupDlg.AllowMargins = False
setupDlg.AllowOrientation = False
setupDlg.AllowPaper = False
setupDlg.AllowPrinter = False
setupDlg.Reset()
printDoc.DefaultPageSettings.PaperSize = New PaperSize("A5", 850, 1400)
End Sub
Screenshot
![](https://i.imgur.com/n7uURBY.jpg)
![](https://i.imgur.com/OxxiiCG.jpg)