# Tutorial: Binding to a Corporate Database (Visual Studio 2013 or later)

Discover how to set up a database connection and data set using the Quickstart menu in Visual Studio. Get detailed guidance on choosing the data source, specifying the database model, and including desired database objects.

## Content

The following tutorial walks you through creating a project and binding the Spread control to a database. These instructions are based on the steps required in Visual Studio 2013 or later.

## Step 1 - Add Spread Control to the Project

The following steps will help you in adding Spread control to the project:

1. Start a new Visual Studio .NET project.
2. Provide a name to your project and the form file.
3. Now, add the FpSpread component to your project, and then place the component on the form.

If you do not know how to add the FpSpread component to the project, refer to [Adding a Component to a Visual Studio 2019 Project](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-allcontrol/adding-component-to-visual-studio-2019-or-2022) or [Adding a Component to a Visual Studio 2015 or 2017 Project](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-allcontrol/spwin-vs2015add) or [Adding a Component to a Visual Studio 2013 Project](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-allcontrol/spwin-vs2013add).

## Step 2 - Configure Data Source

In this section, we will use the Quickstart menu to set up the database connection and the data set.

1. Select the form and click the **QuickStart** icon to launch the **FpSpreadTasks** menu as shown in the following image.
    ![FpSpreadTasks menu](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/db/2.png)
2. In the FpSpreadTasks menu, go to **Choose Data Source** and click the drop down button. In the drop down menu that appears, click **Add Project Data Source** to open the Data Source Configuration Wizard.
    ![Choose Data Source dropdown in FpSpreadTasks menu](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/db/3.png)
3. In the Data Source Configuration Wizard, click **Database** and then click **Next**.
    ![Data Source Configuration wizard](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/db/4.png)
4. Click **Dataset** to specify the database model that you want to use and then click **Next**.
    ![Selecting Dataset option in Data Source Configuration wizard](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/db/5.png)
5. Under **Choose your Data Connection**, either choose an existing data connection or click **New Connection** and then click **Next** to display the **Add Connection** dialog.
    ![Choosing data connection in Data Source Configuration wizard](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/db/6.png)
6. In the **Add Connection** dialog, click **Browse** to open the **Select Micrsoft Access Database File** dialog.
    ![Add Connection dialog](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/db/7.png)
7. In the **Select Microsoft Access Database File** dialog, make sure the folder path is set to C:\\Program Files (x86)\\Mescius\\Spread.NET 16\\Windows Forms\\v16.0.20221.0\\Samples\\C#\\Common\\Spread.Common.DataStore\\Data and then click **Open**.
    ![File Explorer](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/db/8.png) You can also click the **Test Connection** button in the **Add Connection** dialog to test the connection. If you do not receive a message stating the "Test connection succeeded" retry this step. If you receive the message "Test connection succeeded," your connection is complete. Click **OK** to close the Add Connection dialog.
8. In the **Data Source Configuration Wizard**, make sure the database file that you had chosen in the above step is displayed under **Choose Your Data Connection**. Click **Next** to proceed.
    ![selecting database file in Data Source Configuration wizard](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/db/9.png)
9. Now, Visual Studio displays a dialog that asks if you want to copy the database file to your project. Click **Yes** to continue.
    ![Visual Studio dialog](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/db/10.png)
10. Under **Save the Connection String to the Application Configuration File**, make sure the box for **Yes, save the connection as** is checked, and accept the default name by clicking **Next**.
    ![image](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/image.23e810.png)
11. Under **Choose Your Database Objects**, click the arrow next to Tables to open the drop-down list of available tables. Click the arrow next to **Products** to display the list of fields in the **Products** table. You can choose any table that you want to include in your form.
    ![image](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/image.b1b7ae.png)
12. In the list of fields, select **Product ID**, **Product Name** and **UnitPrice** as shown in the following image and click **Finish**. You can select as many fields as you want.
    ![image](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/image.5b4b90.png)
13. The **NwindDataSet** is now added to your project. Notice that the column headers in Spread control get changed to the field names (**ProductID**, **ProductName** and **UnitPrice**) fetched from the **Products** table in your database.
    Save your project and run it. You should see a form that looks similar to the following image with table data populated across the spreadsheet.
    ![image](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/image.e195a3.png)
    If your form doesn't look similar to the image shown above, adjust the size of your Spread control and re-check the steps that you have performed so far.

## Step 3 - Improve the Display of Data

In this step, you can change the cell type for one of the columns to display the data from the database in a better way.

1. Double-click on the form to open the code window.
2. Set the cell type for the **UnitPrice** column by adding the following code snippet below the code in the Form\_Load event.
3. Save your project.

The following code snippet can be added to enhance the display of the data fetched from the database.

```csharp
// Bind the component to the data set.
fpSpread1.Sheets[0].AutoGenerateColumns = false;
fpSpread1.Sheets[0].DataSource = dbDataSet;
fpSpread1.Sheets[0].ColumnCount = 2;
fpSpread1.Sheets[0].BindDataColumn(0, "ID");
fpSpread1.Sheets[0].BindDataColumn(1, "Description");
```

```vbnet
' Bind the component to the data set.
fpSpread1.Sheets(0).AutoGenerateColumns = False
fpSpread1.Sheets(0).DataSource = dbDataSet
fpSpread1.Sheets(0).ColumnCount = 2
fpSpread1.Sheets(0).BindDataColumn(0, "ID")
fpSpread1.Sheets(0).BindDataColumn(1, "Description")
```