# Binding to a Data Source

This topic provides you code that  binds the Spread component to a data set. Learn more in documentation.

## Content

The following instructions provide the code necessary to bind the FpSpread component to a data set.
The basic procedure is to bind data either to the sheet directly or to a data model that the sheet uses. This means either using the [DefaultSheetDataModel](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.Model.DefaultSheetDataModel.html) class to construct a data model and then in the [SheetView](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.SheetView.html) class set the [DataModel](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.SheetView.DataModel.html) property to the newly created data model or setting the [DataSource](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.SheetView.DataSource.html) member in the SheetView class.

> !type=note
> **Note:**
>
> * How you handle state management while bound to a database or working with large data sets can affect your application’s performance. You need to set up state management to optimize performance and account for other factors. For more information, refer to [Maintaining State](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-statemgmt).
> * If your data set is not getting updated when you click the Update button, see the information and instructions in [Limiting Postbacks When Updating Bound Data](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-databound/spweb-dbpostbacks) to make sure that you have code in your page load event so that you only re-create the bound data when you are loading for the first time and not overwriting it on each post back.

## Using Code

1. Create a data model and set it equal to a **DefaultSheetDataModel** object, specifying a data set for the new model’s *dataSource* parameter.
    Other parameter options are available for the **DefaultSheetDataModel** constructor. Refer to the [Assembly Reference](/spreadnet/docs/latest/online-asp/overview/assembly-reference) for complete information.
2. Set the SheetView object’s [DataModel](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.SheetView.DataModel.html) property equal to the new data model.

**Example**
This example code binds the FpSpread component to a data set named dataSet1.

```csharp
// Create a data model using a data set.
FarPoint.Web.Spread.Model.DefaultSheetDataModel model = new FarPoint.Web.Spread.Model.DefaultSheetDataModel(dataSet1);
FpSpread1.Sheets[0].DataModel = model;
```

```vbnet
' Create a data model using a data set.
Dim model As New FarPoint.Web.Spread.Model.DefaultSheetDataModel(dataSet1)
FpSpread1.Sheets(0).DataModel = model
```

## Using a Shortcut

Set the FpSpread [DataSource](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.FpSpread.DataSource.html) property.
**Example**
This example code uses the FpSpread [DataSource](/spreadnet/api/latest/online-asp/FarPoint.Web.Spread/FarPoint.Web.Spread.FpSpread.DataSource.html) property to bind to a data set.

```csharp
FpSpread1.DataSource = ds;
```

```vbnet
FpSpread1.DataSource = ds
```

## See Also

[Model Data Binding in ASP.NET 4.5](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-databound/spweb-dbmodel45)
[Using Sheet Models](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-usemodels)
[Maintaining State](/spreadnet/docs/latest/online-asp/overview/spweb-devguide/spweb-statemgmt)