This walkthrough demonstrates the basics of binding a single data field in a SQL Server database to a named range in Microsoft Office Excel 2003. It includes adding controls that enable you to scroll through all the records in the table.

During this walkthrough, you will learn how to:

Create a data source for an Excel project.

Add controls to a worksheet.

Scroll through database records.

Test your project.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

For this walkthrough, you need two named ranges and four buttons on the first worksheet. First, add the two named ranges from the Data Sources window so that they are automatically bound to the data source. Next, add the buttons from the Toolbox.

To add two named ranges

Verify that the My Simple Data Binding.xls workbook is open in the Visual Studio designer, with Sheet1 displayed.

Open the Data Sources window and expand the Customers node.

Select the CompanyName column, and then click the drop-down arrow that appears.

Select NamedRange in the drop-down list, and then drag the CompanyName column to cell A1.

A NamedRange control named companyNameNamedRange is created in cell A1. At the same time, a BindingSource named customersBindingSource, a table adapter, and a DataSet instance are added to the project. The control is bound to the BindingSource, which in turn is bound to the DataSet instance.

Select the CustomerID column in the Data Sources window, and then click the drop-down arrow that appears.

Click NamedRange in the drop-down list, and then drag the CustomerID column to cell B1.

Another NamedRange control named customerIDNamedRange is created in cell B1, and bound to the BindingSource.

To add four buttons

From the Common Controls tab of the Toolbox, add a Button control to cell A3 of the worksheet.

This button is named Button1.

Add three more buttons to the following cells in this order, so that the names are as shown:

Cell

(Name)

B3

Button2

C3

Button3

D3

Button4

The next step is to add text to the buttons, and in C# add event handlers.