ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.Print RDLC Report in Windows Application using C# and VB.Net<p>Hi <a class="username" rel="Prasunjeet"> Prasunjeet</a>,</p> <p>Please refer below smaple.</p> <p>For populating RDLC Report in Windows Application refer below article.</p> <h1 class="header"><a title="RDLC Report in Windows Forms (WinForms) Application using C# and VB.Net'a" href="">RDLC Report in Windows Forms (WinForms) Application using C# and VB.Net</a></h1> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data.SqlClient; using Microsoft.Reporting.WinForms; using System.Drawing.Printing;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data Imports System.Data.SqlClient Imports Microsoft.Reporting.WinForms Imports System.Drawing.Printing</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">private void Form1_Load(object sender, EventArgs e) { Customers dsCustomers = GetData(); ReportDataSource datasource = new ReportDataSource(&#34;Customers&#34;, dsCustomers.Tables[0]); this.reportViewer1.LocalReport.DataSources.Clear(); this.reportViewer1.LocalReport.DataSources.Add(datasource); this.reportViewer1.RefreshReport(); } private Customers GetData() { string constr = @&#34;Data Source=.\Sql2005;Initial Catalog=Northwind;Integrated Security = true&#34;; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT TOP 20 * FROM customers&#34;)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; using (Customers dsCustomers = new Customers()) { sda.Fill(dsCustomers, &#34;DataTable1&#34;); 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(&#34;A5&#34;, 850, 1400); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">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(&#34;Customers&#34;, 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 = &#34;Data Source=.\Sql2005;Initial Catalog=Northwind;Integrated Security = true&#34; Using con As New SqlConnection(constr) Using cmd As New SqlCommand(&#34;SELECT TOP 20 * FROM customers&#34;) Using sda As New SqlDataAdapter() cmd.Connection = con sda.SelectCommand = cmd Using dsCustomers As New Customers() sda.Fill(dsCustomers, &#34;DataTable1&#34;) 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(&#34;A5&#34;, 850, 1400) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="" alt="" width="472" height="231" /></p> <p><img src="" alt="" width="472" height="250" /></p>, 02 Nov 2018 02:24:07 GMT