Standard .NET Data Providers
- 3 minutes to read
This topic explains how to bind reports to data using standard .NET data providers at design time and runtime.
See the Quick Guide to Report Data Binding topic to learn about the other data binding approaches.
Create the following objects to connect a report to a .NET data provider:
- A data connection specifying the database’s location and the method for accessing it.
- A data adapter that serves as a bridge between physical data and a dataset. It uses the data connection object to access a database.
- Once a data adapter has been created and configured, it can generate a DataSet which supplies the report with the actual data.
The following image illustrates the data binding mechanism described above:
.NET data providers allow you to access standard data types which use different connections and data adapters:
- The OleDbConnection and OleDbDataAdapter objects connect to data exposed via the OLE DB.
- The SqlConnection and SqlDataAdapter objects work with data sources provided by Microsoft SQL Server version 7.0 or later.
You can also use different third-party data adapters if they can generate and populate a report’s dataset.
You can bind a report to a DataSet in the following ways:
- By assigning the required table from the dataset to the XtraReportBase.DataSource property.
- By assigning the dataset to the XtraReportBase.DataSource property and supplying the required table’s name when binding a report control to a data column in this table.
- By setting the XtraReportBase.DataSource property to a DataView object bound to a table from the dataset.
You need to fill the dataset with data manually by calling the data adapter’s Fill method. For instance, you could do this before previewing or printing the report. However, you can avoid manually filling the dataset by setting the XtraReportBase.DataAdapter property to the data adapter that was used to create the dataset. In this case, the report automatically populates the dataset with data.
It is possible to load only a predefined number of records from a dataset, which can reduce the load on your database server and the time it takes to generate a report when working with large datasets.
Use the XtraReport.PreviewRowCount property to limit the number of data records displayed in a report. It is set to zero value by default, meaning that this property is ignored.
When a bound data source contains more than one data table, you can use the XtraReportBase.DataMember property to specify the list in the data source (normally, this is a table) whose data is used by a report control. This property is set automatically in most cases, but you can change its value if required.