Print RDLC Report in Windows Application using C# and VB.Net

Last Reply 4 months ago By pandeyism

Posted 4 months ago

Hello there,

hows u all?

I am beginner in C# I want to know some more extra techniques.

I have created an windows form application and I want to print the invoice using RDLC reporting method.

i want to print the invoice in A5 Paper Size. 

Thank you I hope I will get positive response from all of u.

Posted 4 months ago Modified on 4 months ago

Hi Prasunjeet,

Please refer below smaple.

For populating RDLC Report in Windows Application refer below article.

RDLC Report in Windows Forms (WinForms) Application using C# and VB.Net



using System.Data.SqlClient;
using Microsoft.Reporting.WinForms;
using System.Drawing.Printing;


Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
Imports System.Drawing.Printing



private void Form1_Load(object sender, EventArgs e)
    Customers dsCustomers = GetData();
    ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);

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)
    PageSetupDialog setupDlg = new PageSetupDialog();
    PrintDocument printDoc = new PrintDocument();
    setupDlg.Document = printDoc;
    setupDlg.AllowMargins = false;
    setupDlg.AllowOrientation = false;
    setupDlg.AllowPaper = false;
    setupDlg.AllowPrinter = false;
    printDoc.DefaultPageSettings.PaperSize = new PaperSize("A5", 850, 1400);


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))
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
    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
    printDoc.DefaultPageSettings.PaperSize = New PaperSize("A5", 850, 1400)
End Sub