This walkthrough explains the steps involved in connecting to an XML data source and creating a dataset. It also demonstrates the use of the List control.
The walkthrough is split up into the following activities:
- Creating a Data Dynamics Report
- Connecting the report to an XML data source
- Adding a Dataset
- Adding controls to the report to contain data
- Viewing the report
To complete the walkthrough, you must have access to the Factbook sample database included with this installation.
Creating a Data Dynamics Report
To create a report in Visual Studio
- Create a new project in Visual Studio.
- From the Visual Studio Project menu, select Add New Item.
- In the Categories pane, select Data Dynamics Reports.
- In the Templates pane, select Report and name the report ExchangeRates.rdlx.
- Click Add in Visual Studio 2005.
Connecting the report to a data source
To connect the report to a data source
- If the Data Explorer is not in view, from the View menu, select Other Windows, then Data Dynamics Reports Data Explorer (at the bottom).
- Click the Add icon and select the Data Source... option.
- In the Report DataSource smart panel that appears, select the General page.
- Change the Name to Factbook.
- Check the Shared Reference checkbox.
- Click the Browse button and select Factbook.rdsx, which is located in C:\My Documents\Data Dynamics\Reports\build number\Samples\Factbook.
Note: In Windows Vista, the path is C:\User\your name\Documents\Data Dynamics\Reports\build number\Samples\Factbook\.
- Click the Accept button in the lower right corner to close the smart panel and see Factbook appear in the Data Explorer.
Adding a dataset
To add a dataset
- Click the Add icon and select the Data Set... option.
- In the DataSet smart panel that appears, select the General page.
- Change the Name to ExchangeRates.
- On the Query page, enter the following XML path into the Query text box to access data for every country except "World":
//country [@name != 'World']
- On the Fields page, enter the values in the table below to create fields for your report. Values for XML data fields must be valid XPath expressions.
Field Name Type Value Name Database Field @name Currency Database Field ./ExchangeRates/Currency 2004 Database Field ./ExchangeRates/VsUSD2004 2003 Database Field ./ExchangeRates/VsUSD2003 2002 Database Field ./ExchangeRates/VsUSD2002 2001 Database Field ./ExchangeRates/VsUSD2001 2000 Database Field ./ExchangeRates/VsUSD2000
- Click the Accept button in the lower right corner to close the smart panel and see ExchangeRates and the fields appear in the Data Explorer.
Adding controls to contain data
To add controls to the report
- From the Toolbox drag a List data region onto the body of the report and set its DataSetName property to ExchangeRates.
- Resize the List to fill the entire body of the report.
- From ExchangeRates in the Data Explorer, drag the Name field onto the list, center it at the top, and set the font size to 14.
- Drag the following fields onto the list with properties set as described in the table below.
Field Name Location Size Currency 1.125in, 0.5in 2.25in, 0.25in 2004 4.5in, 0.875in 1in, 0.25in 2003 4.5in, 1.25in 1in, 0.25in 2002 4.5in, 1.625in 1in, 0.25in 2001 4.5in, 2in 1in, 0.25in 2000 4.5in, 2.375in 1in, 0.25in Note: You will notice that the expressions created for these fields are different than usual. Because Visual Basic syntax does not allow an identifier that begins with a number, any numeric field names must be treated as strings in expressions.
- Drag a TextBox onto the list with properties set as described in the table below to combine static text with a field value.
Value Location Size ="Value of " & Fields!Currency.Value & " versus US$ for year:" 0.125in, 0.875in 3in, 0.25in
- Drag TextBox controls onto the list with properties set as described in the table below to create static labels.
Value Location Size Other Currency: 0.125in, 0.5in 0.75in, 0.25in Bold 2004: 3.375in, 0.875in 1in, 0.25in TextAlign=Right 2003: 3.375in, 1.25in 1in, 0.25in TextAlign=Right 2002: 3.375in, 1.625in 1in, 0.25in TextAlign=Right 2001: 3.375in, 2in 1in, 0.25in TextAlign=Right 2000: 3.375in, 2.375in 1in, 0.25in TextAlign=Right
- From the File menu, select Save.
Viewing the report
Any report designed with Data Dynamics Reports can be opened in the included Data Dynamics Reports Viewer application or you can view it at design time.
To view the report at design time
- Click the Preview tab of the report designer.
To view the report at run time
- Add the ReportPreview control to your Visual Studio toolbox and drop it onto your Windows form.
- Set the Dock property of ReportPreview1 to Fill so that it will automatically resize if the form is resized at run time.
- Double-click the viewer to go to the Load event and use code like the following.
'Visual Basic.NET Dim rpt As New System.IO.FileInfo(Application.StartupPath & "..\\..\\ExchangeRates.rdlx") Me.ReportPreview1.OpenReport(rpt)
//C# System.IO.FileInfo rpt = new System.IO.FileInfo(Application.StartupPath + @"..\..\..\ExchangeRates.rdlx"); this.reportPreview1.OpenReport(rpt);
- Run the project.