Load RDLC Report Using Report Viewer Programmatically
This tutorial will guide you on how to programmatically load the RDLC Report into Report Viewer Control.
I search the internet on how to do this but I can’t find one. There are answers in some forum site but the solution is not clear and don’t have a sample source code.
In my previous tutorial I discuss the solution for the error “The definition of the report 'Main Report' is invalid”. This time let’s talk about on how we can load the RDLC report programmatically using its own DataSet.
The source code I implemented here is very simple but it’s the best solution. Unlike with other samples on the internet, they use a lot of code to do a very simple task.
Here’s a sample of the code to display the RDLC Report programmatically.
- Private Sub frmReport_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
- Dim rptDataSource As ReportDataSource
- Try
- With Me.ReportViewer1.LocalReport
- .ReportPath = "Reports\" & strReport & ".rdlc"
- .DataSources.Clear()
- End With
- Select strReport
- Case "Employees"
- Dim ds As New Load_RDLC_Report_Programmatically.EmployeesDataSet
- Dim da As New Load_RDLC_Report_Programmatically.EmployeesDataSetTableAdapters.EmployeesTableAdapter
- da.Fill(ds.Employees)
- ' Use the same name as defined in the report Data Source Definition
- rptDataSource = New ReportDataSource("EmployeesDataSet", ds.Tables("Employees"))
- Case "Customers"
- Dim ds As New Load_RDLC_Report_Programmatically.CustomersDataSet
- Dim da As New Load_RDLC_Report_Programmatically.CustomersDataSetTableAdapters.CustomersTableAdapter
- da.Fill(ds.Customers)
- ' Use the same name as defined in the report Data Source Definition
- rptDataSource = New ReportDataSource("CustomersDataSet", ds.Tables("Customers"))
- End Select
- Me.ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
- Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
- Catch ex As Exception
- MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
Download the source code and try for yourself. Don’t hesitate to ask questions by leaving a message below.
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Comments
help
Thank you very much. This is
Thanks!
- //property
- public string report;
- private void Form1_Load(object sender, EventArgs e)
- {
- const string rut = "Reporting.Reports.";
- switch (report)
- {
- case "CustomerList":
- da.Fill(ds.CustomerList);
- reportDataSource.Value = da.GetData();
- break;
- //default:
- }
- reportViewer1.LocalReport.ReportEmbeddedResource = rut + report + ".rdlc";
- reportViewer1.LocalReport.DataSources.Clear();
- reportViewer1.LocalReport.DataSources.Add(reportDataSource);
- reportViewer1.RefreshReport();
- }
Programmatically Load RDLC
MySQL + ODBC 3.51 + Visual Studioo 2010
What if EmployeeTableAdapter had Parameter
Yes, that's correct. I
Error in local report processing
Hi!
I'm developing a Windows form Application (c#) using vs2010 I have created the .rdlc report and under report data I gave the parameters for each field. then in the form I gave the following code for a button click even of a button named " view report" where the user gives the primary key value to display the relevant report.
but when I run the application and after clicking that button an exception occurs saying
Microsoft.Reporting.WinForms.LocalProcessingException was unhandled
Message=An error occurred during local report processing.
here's the code I gave
private void button1_Click(object sender, EventArgs e)
{
SqlConnection myconnection1 = new SqlConnection("user=sa;" + "password=123;" + "server=USER-PC\\SQLEXPRESS;" + "Trusted_Connection=Yes;" + "database=Hematology;" + "Connection timeout=30;");
myconnection1.Open();
SqlCommand report = new SqlCommand("Select * FROM Patient p, BMarrow b WHERE p.BHT=b.BHT AND p.BHT= '" + textBox1.Text + "';", myconnection1);
SqlDataReader reader2 = report.ExecuteReader();
if (reader2 != null)
{
if (reader2.Read())
{
//this form has reportviewer 1 and report1.rdlc is the report viewd in that report viewer
/*I have created 3 datasets under report data and dataset1 stands for the 'Patient' table and datase2
stands for the 'BMarrow table' from those two daasets I have dragged and dropped the attributes
into the text boxes in report1.rdlc*/
ReportParameterCollection reportParameters2 = new ReportParameterCollection();
reportParameters2.Add(new ReportParameter("Name", reader2.GetValue(0).ToString()));
reportParameters2.Add(new ReportParameter("Age", reader2.GetValue(1).ToString()));
reportParameters2.Add(new ReportParameter("Sex", reader2.GetValue(2).ToString()));
reportParameters2.Add(new ReportParameter("Ward", reader2.GetValue(3).ToString()));
reportParameters2.Add(new ReportParameter("BHT", reader2.GetValue(4).ToString()));
reportParameters2.Add(new ReportParameter("Indication", reader2.GetValue(5).ToString()));
reportParameters2.Add(new ReportParameter("BM", reader2.GetValue(6).ToString()));
reportParameters2.Add(new ReportParameter("Difficulty", reader2.GetValue(7).ToString()));
reportParameters2.Add(new ReportParameter("SiteOfAspiration", reader2.GetValue(8).ToString()));
reportParameters2.Add(new ReportParameter("Cellularity", reader2.GetValue(9).ToString()));
reportParameters2.Add(new ReportParameter("Erythropoiesis", reader2.GetValue(10).ToString()));
reportParameters2.Add(new ReportParameter("Granulopoiesis", reader2.GetValue(11).ToString()));
reportParameters2.Add(new ReportParameter("Megakaryocytes", reader2.GetValue(12).ToString()));
reportParameters2.Add(new ReportParameter("Abnormal", reader2.GetValue(13).ToString()));
reportParameters2.Add(new ReportParameter("SpecialStains", reader2.GetValue(14).ToString()));
reportParameters2.Add(new ReportParameter("Lymphocytes", reader2.GetValue(15).ToString()));
reportParameters2.Add(new ReportParameter("Conclusion", reader2.GetValue(16).ToString()));
reportParameters2.Add(new ReportParameter("Date", reader2.GetValue(17).ToString()));
this.reportViewer1.LocalReport.SetParameters(reportParameters2);
}
}
what is wrong with this??? I can't understand :( I'm new to this I tried searching the internet but didn't find a solution
rdlc dynamic column change using c#
how can i modify the rdlc report using c# and
please provide code
and also tell me that how can i pick the .png images using
external images from the folder of images in project
Add new comment
- Add new comment
- 5280 views