Current filter:
                                You should refresh the page.
                                  • How to connect a data-aware control to a database and configure the data connection options by using the SqlDataSource component?

                                1 Solution

                                Creation Date Importance Sort by

                                By following these steps, I've configured the SqlDataSource component and provided data for the DevExpress Data Grid

                                1. Locate the SqlDataSource component in the ToolBox (DX,14.2: Data & Analytics) and drop it onto a form.
                                2. This will invoke the data configuration dialog. You can also invoke it manually by clicking the 'Configure Connection..' smart tag menu item.On the first page of the invoked Data Source Wizard, select Database and click Next.

                                3. Specify data connection
                                You can use an existing or create a new data connection.
                                I've selected "No, I'd like to specify the connection parameters myself" and clicked Next.

                                4. On the next page, set a custom connection string or select from the supported data source types. Depending on the data provider selected, it may be necessary to specify additional connection options (such as authentication type and database name) on this page.

                                In this example, the GridControl will be bound to the Categories data table provided by the Northwind database.
                                Note: you can find the nwind.mdb file in the directory where you installed the DevExpress demos

                                5. Click Next on the next page to save the created connection string to the configuration file.

                                6. On the next page, it is possible to construct an SQL query to obtain data from the database, or select a stored procedure.
                                I clicked Run Query Builder... to construct an SQL query.

                                7. In the invoked Query Designer window, I dragged the Categories item from the list of available tables on the left and dropped it on the list of data tables to be used.

                                I checked the required fields of the Categories table and clicked OK to exit the Query Designer. Click Finish in the Data Source Wizard to exit the wizard.
                                The next step is to bind a GridControl to this data source.

                                8. Place the GridControl onto a form and assign the SqlDataSource component to the GridControl.DataSource property. Assign "Categories" to the GridControl.DataMember property.
                                9. The final step is to retrieve data. To do so, call the SqlDataSource.Fill method. I did this in the form Load event handler:

                                private void Form1_Load(object sender, EventArgs e) { sqlDataSource1.Fill(); }

                                As a result, the Grid Control is bound to the data table. The attached video illustrates this. 

                                You will also find an example that shows how to provide an SQL Data Source with a Master-Detail Relation at How to: Bind a Report to a Database.

                                The following code example demonstrates how to bind the GridControl to a Microsoft SQL Server database through the SqlDataSource component:
                                How to configure the SQL Data Access component in code to bind the GridControl to a database

                                See also:
                                Binding to SQL Data
                                SqlDataSource - How to change connection parameters at runtime

                                • Lisa Bencic 07.14.2015

                                  Can this be expanded to show how to actually edit / add / remove data?

                                • Nadezhda (DevExpress Support) 07.14.2015
                                  Hello Lisa,

                                  SqlDataSource to connect a Windows Forms control to a database in read-only mode. If you want to use in-place editing, I suggest that you use ADO.NET. Please refer to this document to learn how to bind an ADO.NET DataSet to the GridControl: How to: Bind GridControl to Database and Implement Master-Detail Mode at Design Time
                                  Let us know if we can be of more help.
                                • Ron McCain 09.06.2016
                                  please provide this example for ASP.NET  C# with datasource in codebehind bound to grid in aspx file
                                • Nadezhda (DevExpress Support) 09.06.2016


                                  I've created a separate ticket on your behalf (How to use the SqlDataSource component to provide data for the ASPxGridView). It has been placed in our processing queue and will be answered shortly.
                                  Note that in this thread, we illustrate how to work with our SqlDataSource component. However, as far as I understand, you wish to use a standard SqlDataSource. Please clarify this.