SqlDataSource Class
The data source for Windows Forms data-aware controls that binds these controls to a database (in read-only mode) while allowing you to configure the data connection options.
Namespace: DevExpress.DataAccess.Sql
Assembly: DevExpress.DataAccess.v17.2.dll
Declaration
[ToolboxTabName("DX.17.2: Data & Analytics")]
[XRDesigner("DevExpress.DataAccess.UI.Design.XRSqlDataSourceDesigner,DevExpress.DataAccess.v17.2.UI", typeof(IDesigner))]
[ToolboxBitmap(typeof(ResFinder), "Bitmaps256.SqlDataSource.bmp")]
public class SqlDataSource :
DataComponentBase,
IListSource,
IDataConnectionParametersService,
IListAdapterAsync,
IListAdapter
Related API Members
The following members accept/return SqlDataSource objects:
Remarks
The SqlDataSource component is intended to create and configure database access to various data-aware controls in WinForms applications. Use it to provide database access to a GridControl, TreeList, ChartControl or any other DevExpress control that can be configured via the Data Source Configuration Wizard.
The SqlDataSource supports the following data providers.
- Amazon Redshift
- Firebird
- Google BigQuery
- IBM DB2
- Microsoft Access 2007
- Microsoft Access 97
- Microsoft SQL Server
- Microsoft SQL Server Compact Edition
- MySQL
- Oracle
- Pervasive PSQL
- PostgreSQL
- SAP Sybase Advantage
- SAP Sybase ASE
- SAP Sybase SQL Anywhere
- SQLite
- Teradata
- VistaDB
- VistaDB5
- XML file
The SqlDataSource maintains the collection of individual SqlDataSource.Queries, along with a collection of their master-detail SqlDataSource.Relations.
Design-Time Specifics
To manage the data connection settings without writing any code, the SqlDataSource includes a Query Builder, providing a graphical user interface (GUI) for quick and easy customization of data connection options.
The Query Builder supports the following three query types:
- tables (SelectQuery);
- stored procedures (StoredProcQuery);
- custom SQL (CustomSqlQuery).
Once added to an application, you can configure the data source by using the commands available in the component’s smart tag.
The following commands are available.
Configure Connection…
Corresponds to the SqlDataSource.ConfigureDataConnection method that invokes the Connection Editor.
Manage Queries…
Corresponds to the SqlDataSource.Queries property that is used to access the collection of queries. The following image illustrates the Manage Queries dialog.
Manage Relations…
Corresponds to the SqlDataSource.Relations property that is used to access the collection of data relations.
This command is available when there are two or more queries in the collection.
The following image illustrates the Master-Detail Relation Editor.
Rebuild Result Schema
Corresponds to the SqlDataSource.RebuildResultSchema method that updates the result schema available on the client after query execution (it can be accessed using the SqlDataSource.Result property). This command does not affect the actual database schema on the server.
When using a SqlDataSource to bind an XtraReport to data, call the RebuildResultSchema method to make the data source structure displayed in the Field List of an End-User Report Designer. For a code sample, see Bind a Report to a Microsoft SQL Server Database (Runtime Sample).
Request Database Schema
Corresponds to the SqlDataConnection.GetDBSchema method that returns the schema of the database from the server and updates the result schema on the client.
Note
Certain controls (e.g., the GridControl) do not automatically retrieve data when bound to the SqlDataSource component, and require calling the SqlDataSource.Fill method manually. See the Binding to SQL Data topic for an example.
When using a SqlDataSource to bind an XtraReport to data, the Fill method is called internally when a report document is generated by using the XtraReport.CreateDocument or IReportPrintTool.ShowPreview method.
Runtime Specifics
To configure a data connection in code, you can use the methods of the SqlDataSourceUIHelper class (requires referencing the DevExpress.DataAccess.v17.2.UI.dll assembly to an application).
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the SqlDataSource class.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.