Solved

How does Microsoft reporting work

Posted on 2009-05-04
12
493 Views
Last Modified: 2013-11-07
Hi Experts,

I'm writing a VB.Net 2005 application.  .Net Framework 2.

I would like to incorporate a few Microsoft reports(rdlc) in my application.  These won't run off a SSRS server.  They'll be local reports.

I can't seem to get the syntax working.  Can someone please provide me with an exact code snippet?  Let's say I have a report called "Report1.rdlc" in my project.

In Private Sub ExportReport
    ....  code goes here
End Sub

I need to load the report file and/or load the report defition.  I keep getting errors that say the repord defition hasn;t been loaded.  Then I need to add a datasource to the report and pass though a datatable or dataset.  Then I need to export the report to a PDF file on disk.

I've been struggling to get this working. Please provide me with code snippet that works.

Thanks
0
Comment
Question by:PantoffelSlippers
  • 6
  • 6
12 Comments
 
LVL 8

Accepted Solution

by:
RyanAndres earned 300 total points
ID: 24296541
Use the ReportViewer component in your form.
ReportViewer viewer = new ReportViewer();

DataTable dt = new DataTable(); //  Change this to your datatable

ReportDataSource ds = new ReportDataSource("DataSet", dt); // Change this to your dataset name defined int he report file

lr.DataSources.Add(ds);

viewer.LocalReport.DisplayName = "Report Name";

viewer.LocalReport.ReportPath = @"C:\report.rdlc";

viewer.LocalReport.Refresh();

viewer.RefreshReport();

Open in new window

0
 
LVL 8

Assisted Solution

by:RyanAndres
RyanAndres earned 300 total points
ID: 24296548
This is the VB code:
Dim viewer As New ReportViewer()

Dim dt As New DataTable()

' Change this to your datatable

Dim ds As New ReportDataSource("DataSet", dt)

' Change this to your dataset name defined int he report file

lr.DataSources.Add(ds)

viewer.LocalReport.DisplayName = "Report Name"

viewer.LocalReport.ReportPath = "C:\report.rdlc"

viewer.LocalReport.Refresh()

viewer.RefreshReport()

Open in new window

0
 

Author Comment

by:PantoffelSlippers
ID: 24297420
Thanks Ryan

I'll give that a shot but I really needed to export to PDF as the original post requests.

I think there's a render method  but I cant get it to work.

Thanks

0
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24297465
The ReportViewer component allows you to save as a PDF file. It can also export to an excel file.
0
 

Author Comment

by:PantoffelSlippers
ID: 24315132
Can I have a ReportViewer component without having a form?
0
 

Author Comment

by:PantoffelSlippers
ID: 24315518
RyanAndres:

In your code:

What is lr?   LocalReport I presume?

Also, after the viewer is refreshed, how do I get the PDF?


Thanks
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:PantoffelSlippers
ID: 24316069
RyanAndres,

IN your code you pass through a datasource which is called "Dataset".

Does this mean that in your report, there needs to be a datasource of the same name?
0
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24316149
That is correct.
0
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24316321
lr is LocalReport.

The ReportViewer component includes the save toolstrip item / button and you have the option to save as pdf or xls.

The ReportViewer component requires the following references:
Microsoft.ReportViewer.Common
Microsoft.ReportViewer.WinForms
System.Windows.Forms

However, you cannot display a reportviewer component in a console window :]
0
 

Author Comment

by:PantoffelSlippers
ID: 24316813
RyanAndres,

Thank you.  I have a few comments though....

You add the datasource to lr which is a LocalReport.

Then ReportViewer displays its localreport but there is no line of code that states that ReportViewer's localreport is lr.

Regarding the export of PDF:  I was planning to produce these PDF's from a Windows service with no user interface, therfore no form and no user to click export.  I do know that LocalReport has a Render method that does this but I can't get the syntax right.

Any idea how this method works?

Thanks
0
 
LVL 8

Assisted Solution

by:RyanAndres
RyanAndres earned 300 total points
ID: 24316895
Sorry I took this code from different areas of my own code.

This line:
lr.DataSources.Add(ds);

Should be:
viewer.LocalReport.DataSources.Add(ds);

Sorry but I haven't rendered a report outside of a form before. I'm sure you can get an answer on EE. :]
0
 

Author Closing Comment

by:PantoffelSlippers
ID: 31577602
Thank you very much for the effort - it's not a complete solution though.

Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, In my previous Article  (http://www.experts-exchange.com/Database/Reporting/A_15199-Introduction-to-Microstrategy.html)I discussed some basic understanding of Microstrategy that how we can get in Intro of Microstrategy (MSTR). Now it's tim…
Hello, In my precious Article  (http://www.experts-exchange.com/Database/Reporting/A_15280-Create-Project-in-Microstrategy-Part-I.html)we saw the Configuration part for Microstrategy which included Metadata Creation and DataSource Preparation as …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now