Introduction
We will discuss how to bind data to a GridView using MySQL Server. Here we will explain an MVC application; we will create a database schema in MySQL. In Visual Studio we added a connection to our database.
Here we have to start by creating a new ASP.Net MVC Application and bind the data through GridView with MySQL server database.
We have to follow these steps to create a new ASP.Net MVC web Application.
Step 1. Launch Visual Studio 2010.
Step 2. Select menu options File->New Project.
Step 3. In the new project, select a language and select the ASP.Net MVC Web Application.
Step 4. Under the Toolbox, we find the GridView Control. Drag and drop this control onto the Index.aspx page, and under the task menu items, choose a data source.
Step 5. Click on the <New Data Source...> item in Choose data source. This will bring up the Data Source Configuration wizard. Here we need to choose a source of the data we are trying to bring into the application to be bound to the GridView control.
Step 6. Here in this wizard are several options, and we will be using data from a database. Click on the Database icon, as shown in the previous figure. With this, we will be specifying an instance of SQLDataSource2 as our source of data. Click OK.
After the ok button, the next window is shown here. Here we will try to establish a connection to the data source. In the combo box shown, you may see some of the existing connections you have previously established, one of which may initially show up. From here on, we will be making a new connection. Click the New Connection button.
Step 7. Enter the information to connect the selected data source and test the connection.
Step 8. Select the connection we have to make earlier to the mcn database. If not already done so, we can create the new connection at that time by clicking New connection.
Step 9. After selecting the table, we also have to select the columns to be printed.
Step 10. Define custom statements which are given below.
Step 11. Here we are to find many tables attached to select the database (mcn) and select a table.
Step 12. After selecting a table we have to bulid the query and test query.
Step 13. Build the application and run it in the browser. See below.
Resources
Here are some useful resources.