Friday, April 23, 2010

Creating Reports with Visual Express Editions

I haven't seen many write ups on how to create reports using Microsoft's Visual Express Versions. I myself had a rough time trying to figure it out but it's kind of simple, Hopefully this helps someone.

Requirements
 - Visual Web Developer Express
 - Visual VB.Net Express or Visual C#

To begin, if you don't already have Visual Web Developer please download it and install it on your computer. Once installed Create  a new Project after which click on Website->Add New Item

From the Visual Studio INstalled Templated choose Report

This will create a new report in the website, Go ahead and add a datasource to the report by going to Report->Data Sources

Set everything up to the datasource, once the datasource is created you can start dragging fields on to your report, please note you can not place datasource fields on the header or footer

Once you have your report formatted and laid out,  go to your c# or vb.net program and add a report viewer control to your form, This control is not by default on your toolbox, and you must add it through Choose Tools->Choose ToolBox Items, From the .Net Framework Components, Choose the control ReportViewer Make sure you choose the WinForms reports vs the Web

Once you check it off click ok and you should see it appear on your toolbox, now just drag the control to your form, and your half way there, 


When you add the datasource to the report via the above steps  make sure you remember the name you used, To get the report going on the code side of things is really easy, You can either drag a datasource to your form or you can create one with code, it's up to you, 


Before you start coding the report you need to make sure you import , or use the following library


using Microsoft.Reporting.WinForms;


When the report loads it needs to look for the report you created in Web Developer to point to the report on web developer simply add the following code on the load subroutine of the form


this.reportViewer1.LocalReport.ReportPath = "point to the path of the report"


then make sure you load the datasource which ever you choose to do it before you refresh the report


ReportDataSource RDS = new ReportDataSource("dataSet1", this.dataSet1.Tables[0]);
RDS.Name = "name of report source";
this.reportViewer1.LocalReport.DataSources.Add(RDS);


Make sure above the RDS.Name has the name you have on the visual web developer, otherwise it wont load the report correctly,  after the above code you can call the

this.reportViewer1.RefreshReport();


THis will load the report with the same data you had on the visual Web Developer.

And thats all, when you run the form it will load the report based on the dataset you have,


No comments: