Pro SQL Server 2012 Reporting Services

(sharon) #1
CHAPTER 9  RENDERING REPORTS FROM .NET APPLICATIONS

Figure 9-5. Local report in the designer


Now you have a report that uses the dataset you created as a data source. Add the code shown in
Listing 9-3 to the runLocal button’s click event to populate the dataset and display the values in the
Report Viewer control using the .rdlc file you have created. Make sure the ViewerRVC.cs form is open in
design view, and double-click the Run Local button. This will create an empty method to handle the
button’s click event.


Listing 9-3. runLocal click Event: Running Report in Local Mode


private void runLocal_Click(object sender, EventArgs e)
{
Employees empDS = new Employees();
empDS.ReadXml(@"C:\Temp\EmployeePay.xml");
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.LocalReport.ReportEmbeddedResource = "SSRS_Viewer_RVC.EmployeePay.rdlc";
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("Employees_EmployeePay",
empDS.Tables["EmployeePay"]));
reportViewer.RefreshReport();
}


 Note The ReportEmbeddedResource value must include the namespace of your project. If you entered spaces


for the name of your project when you created it, the namespace will use underscores in place of each space.


Now run the project, not the whole solution, in debug mode. Remember you can do this by right
clicking the specific project and selecting Debug -> Start new instance. When the form displays, click
Run Local. This renders the localEmployee Pay report. At this point, you should see something like
Figure 9-6. You’ve now created a report viewer in a Windows Forms application by using the
WebBrowser control with URL rendering and by using the new Report Viewer control. You could stop at

Free download pdf