Creating Reports in VS 2010
Creating Reports in VS 2010
Creating Reports in VS 2010
III
Contents
RBDMS Report Creation Process in Visual Studio 2010 Projects .................................................1
Major Changes in Microsoft Reports ..........................................................................................1
1. The work area: Report Designer controls ................................................................... 2
2. Converting RDLC 2005 files to RDLC 2008 ................................................................... 5
3. Handling underlying queries ...................................................................................... 9
4. Adding a tablix with the Report Wizard .................................................................... 10
5. Adding other output options .................................................................................... 13
Creating a New Project ............................................................................................................. 13
An Abridged and Generic Process for Creating RBDMS Reports in Visual Studio 2010 ............. 16
1. Adding a report to the project .................................................................................. 17
2. Specifying the dataset you will use to bind the report .............................................. 17
3. Adding header and footer information ..................................................................... 17
4. Developing the report body ..................................................................................... 18
5. Creating report parameters for filtering returned datasets and linking subreports ... 20
6. Saving your work ..................................................................................................... 21
Creating and Associating Filters ................................................................................................ 21
Adding Reports to the Application Menu ................................................................................. 23
Testing and Debugging Reports, Filters, and Menus ................................................................. 24
About Subreports ..................................................................................................................... 24
Appendix. Report Designer Updates for Entity Framework Projects ........................................ 25
A data source, usually defined by a query (SELECT, WHERE, ORDER BY) run against a SQL Server
database or a data view within SQL Server. Multiple table adapters that describe a set of these
queries or views can be defined as a dataset within a Reports project in VisualStudio.NET 2008
and 2010. This dataset specifies the data source for purposes of report data binding. Visual
Studio 2010 also gives developers the option of using an ADO.NET Entity Data Model (.edmx) as
a binding source (see the Appendix).
A template with data fields bound to the fields exposed in the table adapter or view.
A filter that contains elements compatible with the query or view and that is associated with the
report parameters, the values of which may be defined programmatically by the host
application or passed from one report to another.
Whats the difference between RDL and RDLC files? Report language definition (.rdl) files are
created with the SQL Server 2008 version of the Report Designer and are meant to be run from the Report
Server. Report language definition client (.rdlc) files are created with VS2008 and higher and are client side.
RDL and RDLC formats have the same xml schema. However, in RDLC files, some values (such as query text) are
allowed to be empty, which means that they are not immediately ready to be published to a Report Server. The
missing values can be entered by opening the RDLC file using the SQL Server 2008 version of Report Designer.
(You have to rename .rdlc to .rdl first.)
RDL files are fully compatible with the ReportViewer control runtime. However, RDL files do not contain some
information that the design-time of the ReportViewer control depends on for automatically generating databinding code. By manually binding data, RDL files can be used in the ReportViewer control.
RDLC files require the ReportViewer control, and no preview is available without running the project. However,
RDL and RDLC formats may be converted back and forth, and the RBDMS Reports module can accommodate
either format. Projects must be WinForm to use the VS2008 ReportViewer. WPF can use the ReportViewer
control, but only in Windows compatibility mode. Silverlight supports use of the ASP.NET ReportViewer.
Version 10 of ReportViewer is being used in PA RBDMS, OH RBDMSW and is proposed for use in CO RBDMSW.
This document covers only the client-side processing of reports, since the .rdlc format has proven to be easier
to use with RBDMS applications. This document does not include the steps to run or preview RDLC reports
from within Visual Studio, which requires a separate window with a ReportViewer control to host the RDLC
report.
Reference and further reading: http://www.gotreportviewer.com/.
2. The report designer supports the RDL 2008 schema, and support for the RDL 2005 schema has
been dropped other than in local processing mode. Therefore, when you open your existing RDL
2005 reports in the Report Designer, you will need to upgrade them. Additionally, the
conversion of RDLC files from the 2005 schema to the 2008 was found to work well.
3. The Report Wizard has been very nicely updated to guide you through the required tasks to
create a finished report and new Chart and Gauge wizards have been included for presentation
options.
4. Report export to Microsoft Word, Excel, and comma-separated value lists has been enhanced.
Word export is compatible with version 2000 and higher, and the Excel rendering extension now
supports rendering of subreports and nested data regions.
The work space has undergone a significant facelift in Visual Studio 2010, essentially allowing designers
to work in more of a print-preview mode. The following additional areas, which were previously
somewhat arcane, have been exposed in the report designer work area:
6. The Report Data pane, which is used to add and to define report-specific items such as images and
parameters with right-click functionality.
7. The Row and Column Grouping area, which allows the designer to specify how the displayed
information is grouped for totals and other manipulations.
Another immediately apparent change in Visual Studio 2010 is the ability to drag and drop data fields
from the Report Data pane directly into the report body or to use a field picker from a right click in the
cell. This vast improvement speeds layout development by eliminating endless scrolling in an
inconveniently placed Properties control or typing =Fields!Blah.Value in every cell to effect data binding
to the source.
Note about the samples and processes discussed herein: The following samples and processes discussed
trace the creation of two report projects in Visual Studio 2010 against SQL Server 2008 databases. The
projects and the discussion of how these report processes have been updated in were created for
illustrative (classroom) purposes only.
The process of adding the report to an RBDMS front-end application and building the necessary filter
sets and menu objects within the RBDMS Admin application(s) remains essentially the same across both
the WinForm and Silverlight versions. The Silverlight version of RBDMS Admin offers the added ability to
specify filtering wizards.
6. Choose to convert to the RDLC 2008 format so that you can get all of the nice editing features:
Should you convert to RDLC 2008? Is converting to ReportViewer version 10 a good idea for
your installation?
Existing code base for RBDMS.NET installations in MS, OK, and possibly others uses ReportViewer version 9
(.RDLC 2005). PA RBDMS.NET, OH RBDMSW, and (soon) CO RBDMSW use ReportViewer version 10. Unless you
(or your developer) are prepared to recompile the application with updated references to ReportViewer
version 10 in RbdmsWpfControlsBase, do not even consider converting your existing reports to RDLC 2008.
They will no longer work!
Updating an application to version 10 of the ReportViewer requires removing the references to version 9,
adding the version 10 references, compiling the Visual Studio solution and re-deploying. Current version 9
users should consider combining this with the next version upgrade of their application.
To safeguard against .sql injection attacks, RBDMS developers then parse out the WHERE clause
programmatically.
The Visual Studio 2010 report designer does not include any .sql in .rdlc files. This is an example of the
<Query> tag in Visual Studio 2010 for a dataset specification:
<Query>
<DataSourceName>PARBDMSDataSet</DataSourceName>
<CommandText>/* Local Query */</CommandText>
</Query>
<rd:DataSetInfo>
<rd:DataSetName>rptHFProduct</rd:DataSetName>
<rd:SchemaPath>C:\Projects\PA\ReportsPA\ReportsPA\rptHFProduct.xsd</rd:Sche
maPath>
<rd:TableName>rptHFProduct</rd:TableName>
<rd:TableAdapterFillMethod>Fill</rd:TableAdapterFillMethod>
<rd:TableAdapterGetDataMethod>GetData</rd:TableAdapterGetDataMethod>
<rd:TableAdapterName>rptHFProductTableAdapter</rd:TableAdapterName>
</rd:DataSetInfo>
Therefore, depending on the circumstances of the specific report, the programmer must either insert
the SELECT statement with a paste operation regardless of the data source (see Appendix) or execute
logic similar to that being used in the PARBDMS project. If the local query message is in the command
text, then we can use SELECT * From " whatever is inside <rd:tablename>. For example, the following
code snippet was added in a ProcessReport and getSubQueryParams:
ndCmdText = elm2.GetElementsByTagName("CommandText").Item(0)
If ndCmdText.InnerText = "/* Local Query */" Then
m_sql = "select * from " & tblName
Else
m_sql = ndCmdText.InnerText
End If
10
3. Choose the dataset you will use for binding and click Next.
4. Drag and drop the fields for the table into the layout through the Arrange fields dialog.
11
6. Apply a style:
12
7. Click Finish to open your new tablix report and edit it as needed.
13
Therefore, the following example will track the wizard action only through project setup and data source
configuration. We will consider ways to add reports to the project separately. For purposes of this
example, we will create a new report project to hold sample reports from PARBDMS.
1. Open Visual Studio and click File | New Project. The New Project dialog box will open and allow
you to target .NET Framework versions, choose templates, and name the project. Click OK.
2. The Report Wizard and the Data Source Configuration Wizard will both launch. In the Choose a
Data Source Type dialog, choose Database:
14
4. Choose the data connection or click New Connection to configure and test the connection:
15
16
If your change is a minor one of adding or deleting a field from the dataset,
open the [datasetname].xsd file by double-clicking it in the Solution
Explorer, making your change in the table adapter, and saving the file. If
your change is one of altering a view to add a table or significantly change
the returned results, edit the view in SQL Server Management Studio and
save your changes.
2.
In Visual Studio, open the report you want to update with the new data
source.
3.
Refresh the data source for the report within Visual Studio:
a.
In the Report Data pane, right-click the data source and choose
Refresh.
OR
b.
icon.
17
and page numbers for printing [="Page " & Globals.PageNumber & " of " &
Globals.TotalPages].
Hint: Headers and footers may be set to display on every page of the report, or be
excluded from the first and/or last page. This option is a property of the
Header/Footer which can be set in the Header [Footer] Properties dialog. Right-click
in the header or the footer and choose Header [Footer] Properties. Footers should be
used only when the report is long enough to span multiple pages.
Hint: List boxes and tables allow the report to grow, so if you fail build the report
with one of these container controls, the report will stop printing after the first record.
While it is not impossible to add a list box after the template is in a state of advanced
development, it is awkward and not fun.
b. Drag and drop the desired fields from the list in Report Data pane into the table, matrix, or
list control OR click in each cell to select the desired field for binding from the shortcut
menu accessed by the table icon.
c. To change the configuration of the tablix or add an expression, right click in the container
control.
d. Add desired formatting to selected fields through the Properties pane. Use the multi-select
keys (Shift+Click and Ctrl+click) to select groups of fields to receive similar formatting.
e. Right-click on the tablix row header where you would like to add a group for sorting, if your
report will include tabular totals that require specifying a grouping and sort order. The
shortcut menu allows a number of options for revising the tablix organization.
18
The Add Group selection will allow you to specify whether the group you are adding will be
a parent group or a child group. To view the properties of an existing group, select Row
Group from this shortcut menu. Be sure to specify the Group on: option in the Group
Properties dialog.
Hint: If you know that your report will have multiple groups and dynamic content, you
might consider using the Report Wizard to specify the initial layout of the tablix.
f.
To add a total to a grouped column, right click the tablix cell where you want the total to
display and choose Add Total | Column or Row.
19
Other hints for controlling the layout: If you find that you are having
problems with the layout stretching horizontally off your targeted paper size for
printing, be aware of two factors in your debugging:
1.
Make sure you set the CanGrow option on the individual control
properties on your report to False (unless that is desirable behavior).
2.
The reality is that an .rdlc template is basically a text file. Controlling the
placement of elements is often a matter of squish, jiggle, check, re-squish,
jiggle again, recheck, and cuss.
In the Report Data pane menu, right click the Parameters folder and select Add
Parameter. The Report Parameters Properties dialog box will open.
b.
If the parameter will be used to filter the returned data to a specified range (To/From
date range, Operator, Well Type, etc.) in the report, the name should be meaningful
20
enough to link the parameter name to the desired filtering function. You will need to
build a filter control with the same name in RBDMS Admin. Click OK.
ii.
If you are creating the report parameter for linking a subreport, the name should be the
same as the field that will link the subreport to the main report. Be sure to select the
correct data type and indicate whether a blank value is allowed (True). Click OK.
iii.
If the parameter will be used to call a filter set, name the parameter CollName of data
type Text, and enter a default value that will match the name of the filter set you will
build in RBDMS Admin. Click OK.
An RBDMS Convention: The RBDMS.NET developers use the report parameter
CollName to specify the name of the filter set created on the Edit Filters page in
WinAdmin.NET. A report parameter CollName should therefore be added to each
.rdlc file you plan to add to an RBDMS application menu. The Default Value you
specify for the CollName parameter in each report should match the name of the
filter set you define in RBDMS Admin for use with the report. The CollName
parameter therefore serves to associate the report with the desired filter control
collection.
Any other report parameter that you define to be passed to the .rdlc (e.g., start
and end dates, etc.) also must be defined as a filter control in RBDMS Admin and
assigned to the CollName (NameYouChose) filter set on the Edit Filters page of
RBDMS Admin.
You do not have to define a parameter for the filterable columns because those
are appended to the WHERE clause of the sql unless the ParameterOnly option in
the filter control defined in RBDMS Admin is set to True. In this case, the column
does not get added to the WHERE clause and is passed as a report parameter.
c.
Drag the report parameter from the Report Data pane into a textbox control in the correct
position in the report. For example, in the case of a parameter that will be used to filter
data return to a specified StartDate, the correct position probably will be in the report
header. For a parameter that will be used to link a subreport, the correct position will be
some discrete location in the body of the subreport, and the visibility of the textbox control
containing it should be set to Hide.
21
2. In RBDMS Admin, make sure that your database connection is pointed to your correct instance
of the database on the Forms | Configuration Options page, Database Connection tab. If it is
not already pointing to the correct installation, reset the connections
3. With Windows Explorer, copy the .rdlc file you created into the folder shown for the appropriate
report path, as shown in Configuration | Settings page.
4. In RBDMS Admin, select Forms | Edit Filters to open the two-paned page that is used to manage
report filter controls.
5. In the left pane on the New Record row, enter the CollName you specified as a report
parameter in Visual Studio. Enter a description for the filter collection in the Description column.
6. Build the filter collection to include those needed to handle any report parameters that your
users will need to retrieve information. To do this, select the desired filter controls on the right
and then drag and drop them on the Set Name record you created. You may need to build the
necessary individual filter controls in the right pane first by completing the form grid. Be sure to
test any .sql statements included in individual filter controls in SQL Server Management Studio
before using them.
7. Right click the Set Name record to preview the filter.
Hint: You may delete items from your set on the left pane without deleting the control
from the database. However, deleting filter controls from the right pane is a permanent
action.
If you must create a new filter control on the right pane of the Edit Filters page in RBDMS Admin, the
following data dictionary snippet may provide useful hints in how to complete each new control record.
The snippet shows the columns in the DevControls table, which governs the filtering in RBDMS.NET:
Column Name
Data
Type
Length
ControlName
varchar 50
xml
text
Nulls Default
NO
21474836
YES
47
Description
ColumnName varchar 50
YES
Prompt
varchar 50
YES
DataType
varchar 255
YES
ControlType
varchar 255
YES
DefaultValue
varchar 255
YES
22
Column Name
Data
Type
Length
Nulls Default
Description
varchar 255
YES
YES
DefaultCompar
varchar 10
e
YES
YES ((0))
Tooltip
HideCompare bit
InputMask
varchar 50
YES
MinValue
varchar 50
YES
MaxValue
varchar 50
YES
SQL
varchar 1024
YES
DisplayField
smallint 2
YES
ValueField
smallint 2
YES
ListItems
text
21474836
YES
47
Hidden
bit
YES
Format
varchar 50
YES
Format specification
Sort
bit
YES ((0))
Required
bit
YES ((0))
ParameterOnly bit
YES ((0))
23
1. Open RBDMS Admin, switch to the Security tab of the Menus and Security page.
2. In the Rights pane, scroll to the New Record row and specify the right for the report you wish to
add.
3. Expand the Rights record and assign the EveryOne role to the right. Be sure to click off the new
record to commit the write action.
4. Switch to the Menus tab of the Menus and Security page.
5. In the Select Menu dropdown, select Reports. This menu is the live menu for the RBDMS.NET
WPF Reports menu.
6. Add the report .rdlc to the menu by selecting the record in the right pane and dragging it to the
Well Data node in the left pane.
7. Click Save Updates.
About Subreports
Subreports must be developed as separate .rdlcs from the main report and should not have a header or
footer. A main report can contain many subreports. Subreports also may contain their own subreports if
desired, but these must be defined within those subreports (not the main report). As a convention of
the RBDMS developers, subreports are always named with the prefix zz.
You can embed a sub-report into the main report body by selecting the Subreport control from the
Toolbox pane in Visual Studio. When you insert a subreport control on the main report body, you must
specify the data link to the subreport as a named parameter. For example, in MSRBDMS.NET, the
subreport zzConstructCasing is linked to the Well Completions report by the ConstructKey which is
specified as the parameter value ConstructKey in the Subreport Properties dialog. Also in the Subreport
Properties dialog, your entry in the Parameters| Name field of the linked subreport definition must
match the parameter value name (in this example, ConstructKey must be added in the Parameters |
Name field). If you forget to link the subreport properly to the main report, the subreport will not work.
24
The Entity Data model offers the means to flatten portions of highly relational data structures in much
the same way database views can be used. The result is that multiple tables can be queried as a single
logical entity.
The process of vertically splitting one entity across two tables in the Entity Data Model is shown in detail
below. For the example, we will work with the following tables from the RBDMS HF module:
25
Within a Visual Studio 2010 Report project, we can create a model with a single entity representing the
ProductChemical and Chemical tables in the following steps:
1. Add a new model to your project: select Add | New Item.
2.
26
27
4. Use the wizard to select an existing connection to the database or create a new connection.
5. From the Choose Your Database Objects dialog box, select the tables you want to work with.
Leave the Pluralize and Foreign key options checked. Click Finish.
7. Next, merge the ProductChemical and Chemical tables into a single entity:
28
a. Copy the scalar properties for the items of interest from the Chemical entity to the
ProductChemical entity. You can use the multi-select keys to do this copy-and-paste
step:
29
c. A dialog box will ask you if you want to delete the Chemical table. Click No to preserve
the Chemical definition in the store model layer.
d. Click the ProductChemical entity to view the Mapping Details window. (To show the
Mapping Details window, click View | Other Windows | Entity Data Model Mapping
Details.
e. In the Mapping Details window for the ProductChemical entity, click Add a Table or
View and select the Chemical table. This adds the Chemical information to the mappings
for the ProductChemical entity.
f.
Under the Chemical table in the Mapping Details window, map the ChemicalName
column to the ChemicalName property. Also, make sure that the PKey property is
mapped to the PKey column of the Chemical table, like so:
30
31
9. The resulting selection allows report creation from a flattened data object in the same way a
database view now accomplishes the task.
32