Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Collapse]Data Binding Common Concepts
    How to: Bind GridControl to Database and Implement Master-Detail Mode at Design Time
    How to: Bind a Control to a Database at Runtime
    How to: Bind a Control to Data Created at Runtime
    How to: Bind a Control to Data in an XML File
    Traditional Data Binding Methods
    Data Source Configuration Wizard
    Data Binding Mechanism in ADO.NET
    Binding Controls to XML Data
    Binding Controls to Data Created at Runtime
    Add Unbound Data to a Data-Aware Control (XtraGrid, XtraPivotGrid)
    Binding to Excel Data Sources
    Binding to LINQ to SQL Classes
    Unbound Sources
    Binding to Entity Framework Core
    Binding to OData
    Binding to SQL Data
    Data Annotation Attributes
    How to: Add Virtual Rows Using the UnboundSource Component
    Obtaining Fields Available in Data Source
  [Expand]Data Source Wizard
  [Expand]Expressions
  [Expand]Behaviors
  [Expand]Application Appearance
  [Expand]Filtering UI Context
  [Expand]High DPI Support
  [Expand]Scaffolding Wizard
  [Expand]Formatting Values
   HTML Text Formatting
  [Expand]Menus
  [Expand]Tooltip Management
  [Expand]Saving and Restoring Layouts
   Clipboard - Copy and Paste Operations. Data Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Binding to SQL Data

Expanded Binding via the Data Source Configuration Wizard

Expanded Online Video

The most convenient way to bind your control to a SQL data source is using the Data Source Configuration Wizard. To invoke this wizard, click the corresponding link in the control's smart-tag or click the wizard icon. The figure below illustrates how to invoke the wizard for the GridControl.

  1. The first wizard page asks you to choose the technology you would like to use. Select the 'SQL Data Connection' option and click the 'New Data Source' button on the wizard's right, as shown below.

    The message box that will appear tells you that the SqlDataSource component will be added automatically. If you need to modify the data source later, you can use the SqlDataSource's smart-tag. For now, the Data Source Configuration Wizard will automatically open the required dialog.

  2. Utilize the invoked Data Source Wizard to set up the connection and configure query parameters.

  3. Configuration Wizzard automatically adds the required piece of code to your project and you can run the application to see the result.

Expanded Manually Binding via the SqlDataSource Component

Note

The following approach assumes manually adding and customizing the SqlDataSource component mentioned above. This method has a few drawbacks, since you will need to perform more operations, such as dropping the component onto your form from the Visual Studio toolbox, setting several required properties of your control and manually calling the Fill method. Other than that, the two methods are identical. So unless you have a strong necessity to use this approach, we recommend using the Data Source Configuration Wizard instead.

To bind your GridControl to data with the SqlDataSource component, follow the simple steps below.

  1. Locate the SqlDataSource component on the toolbox (the 'Data and Analytics' tab) and drop it onto the form.

  2. Immediately after the component is dropped, the Data Source Wizard appears.
    Tip

    To invoke this wizard manually, click the 'Configure Connection' link within the component's smart-tag.

    Follow these tutorials to set up the connection.

  3. You now have a SqlDataSource component bound to the required data. Next, set this component as the grid control's data source (the GridControl.DataSource property) and the Products table as its data member (the GridControl.DataMember property).

  4. The final step is calling the SqlDataSource.Fill method to retrieve your data. In the code below, the method is called on the FormLoad event.
  5. Launch your application to see the result.

Expanded Binding to SQL Data in Code

The following code illustrates how to bind the GridControl to SQL data at runtime using the SqlDataSource component.

In this example, a CustomSqlQuery is used. To learn about other query types, see the SelectQuery and StoredProcQuery classes' descriptions.

To learn about supported database engines, see the inheritance hierarchy of the DataConnectionParametersBase.

Note that specific controls may need additional customization after the control is bound to a data source. For more information, refer to the documentation of the corresponding control.

How would you rate this topic?​​​​​​​