I need to create a DevExpress report and populate it from a stored procedure.

How do I create a DevExpress report and populate it from a stored procedure?  I want to use VB.Net

Related Articles

... and you 'll find more on the DevExpress Menu

This blog will demonstrate how to create a simple DevExpress report and populate it from a stored procedure.   This is my first exposure to DevExpress reports and I in no way claim to be an expert.  I am blogging the steps I took so that I won’t have to relearn them.  There may be better and quicker ways to do things.  This is in no way a complete tutorial on DevExpress XtraReports, it is only a record of my experiences.
This will be a simple one-page report that includes borders, text, data fields from the stored procedure and data fields supplied by DevExpress.  This will not include any sub-reports or sub-bands.  It is assumed that you have DevExpress, Visual Studio, and SQLServer installed on your PC.
The main steps are:

  • Create the VB.Net project (for testing the query and form)
  • Create (and test) the stored procedure
  • Create the report
  • Add borders, text, and data fields
    • Write the code behind to generate the report

The focus of this blog is not focus on creating the VB.Net project, so that is left to you.
In this example, I will be creating the stored procedure used to provide several of the fields needed to fill out the form.  

Once the stored procedure is complete, create the form.  You must have DevExpress installed in order to do this.  In Visual Studio:

  • Right-click the project
  • Select AddDevExpress Item -> Report…  
  • Name the report and click OK
  • On the Report Wizard form, select the report type (for this, choose Data-bound Report) and click Next
  • Select Database as the data source type and click Next
  • Create/choose data connection
    • Select No if you need to create one
      • Enter the values for each field
      • Click Next
    • Select Yes if you will use an existing one
      • Select the desired data connection
      • Click Next
  • Select the Stored Procedure to use
    • Click the arrow to the left of the check box to expand the list of stored procedures
      • Note, this process may time out.  If so, I just clicked the arrow again and the list of stored procedures came up.
    • Select the desired stored procedure
    • Click Next
  • You are next presented with query parameters and given a chance to preview
    • Put default values for each parameter in the Value column (if desired)
      • The Value contents will be displayed as the default if the user is prompted for them.
    • If you click the Preview button
      • You will see the results of your stored procedure call
      • Click Close
    • Click Next
  • Check the stored procedure name under Data Members to include it
  • Under Data Fields, check all of the fields that you want populated in the detail portion of the report.  These fields will be expanded to take the entire width of the report.  This is a ‘quick and dirty’ way to create a report.  It is pretty basic and does not allow for much flexibility in the detail area.
    • Note that all fields will be available once the report form is created and you will be able to position those at that time.
    • Note that if you do not check any fields, none will be populated on the report form.  This gives you a blank report and is the best solution if you need to insert additional columns between fields.  Click Finish and skip to “Designing the Report”, below. 
  • Click Next
  • The next page allows you to group fields.  This is to allow grouping and sub-grouping in the report.  In this case, none are needed.
  • Click Next
  • Enter the report’s title and click Finish

The form will be displayed with all of the fields listed horizontally, with column headers matching the field name

Designing the Report

A DevExpress XtraReport has multiple sections or bands.  The DevExpress website (

) gives details on Banded Reports.

At this point, the report will be displayed and you should be on the Designer tab.  You must be in Designer mode to make any changes to the form.

Any fields checked above will be included in the Detail band of the report.  Column headings for each field will also be automatically included.  The selected fields will be inserted using the entire width of the Detail band.  You will have to manually adjust them if this is not desired.

Since I did not want all of the fields in the detail band of the report, I chose not to check any fields during report creation.  All of the fields are accessible under the stored procedure name on the Field List tab.  The initial, blank report that was generated for me included only the TopMargin, Detail, and BottomMargin.  Note that other bands can be inserted by selecting the Report Explorer tab and right-click on the report name and select Insert Band -> <Band to insert>.  

 

 

 

 

Once you get all of your bands inserted, you can ‘frame’ the report.  I don’t know if the is the correct term or not, but I mean you can draw the borders, labels, and lines, etc., that define the report.  The two controls I used the most are the XRLabel and XRLine.  Both are listed under DX.18.2: Report Controls in the toolbox.  To add one of these controls (or any control), select it in the toolbox and drag it onto the report.

When you drag a control onto the report, you can move and size the control in the usual way.  Note that the controls have a smart tag that when clicked, opens a form that allows you to edit some of the properties to customize the control.  Note that you can get access to all properties of a control by right-clicking on the control and select the Properties option, or by pressing F4.

 

 

 

Once you get the report designed, you can place the data fields.  The list of data fields is displayed under the stored procedure/query on the Field List tab.  Drag each field to the desired location on the report.

To see what the report will look like, click the Preview tab.  This will run the stored procedure and populate the report fields.  Click the Designer tab to go back to make changes.

To save the report as an .repx file (to be used as a stand-alone report), click the smart tag (red arrow) on the report, and then select Save… (yellow arrow).  Navigate to desired directory, name the report and save as a Report XML File (*.repx).

 

This is just meant to give a high-level overview of creating a report.  I will write another blog on creating a report with sub-reports using queries embedded in each report and sub-report as well as passing parameters and using parameters in the query.
 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences