Link to Us

Simple dataBinding

  • Start a new project and repeat your steps to add a database and bindingsNavigator control
  • Add an access database to your project
    • Select the data menu
    • Select Add New DataSource

menu add new data source

    • Select the database icon and click Next

choose data source type database

    • Select New Connection

choose new connection next

    • If Microsoft Access Database File is not listed in the DataSource click the Change button

change your connection

    • Choose Microsoft Access
    • Click OK

access file

    • Click Browse to find your database file


    • Click OK


    • Click the Next button

config wizard

    • Visual Studio asks you to copy the file into your project. Click Yes


    • Next it asks you to save the connection string. Click next to save your connection in a connection string

connection string

    • Select the your database table you want to access and click Finish


    • It adds 3 files to your project
      • App.config
      • The database
      • And XSD file representing your dataset


The database get copied in two places.

  1. Your project folder
  2. The debug folder

Changes made to the database will be made to the copy in your debug folder because that is where the executable is located

  • Add 3 labels and 3 textboxes to your form
    • Set the labels to static text by changing the text properties
      • Survey ID
      • Survey Name
      • Survey E-mail
    • The textboxes will hold data from our database


  • Add a bindingsSource control to the page

bindingsource in tray

  • Set the DataSource by clicking the dropdown arrow and expanding the nodes until you get to your dataSet

survey dataset

  • Set the DataMember property of the dataSource to your table: Survey

This adds a table adapter and adds code in the form_load to fill your data

Now all you need to do it bind your textboxes

  • Select the first textbox
  • Click on the plus sign next to the dataBindings and select the Advanced property


  • Click the button in the advanced property

You can choose to bind any property of the textbox to a datasource

  • Choose text property and select the Bindings dropdown


  • Open the Form1 list instance and browse down until you get to the surveyID


  • Click OK

no formatting

  • Do the same for the other two textboxes

Now you need to add buttons for navigation

  • Add two buttons and change the text properties to Next and previous


  • Add the following code just below the class definition

Private bindMgr As BindingManagerBase


  • Add this code to the form_load to tie the dataset you created earlier to your bindingManager

bindMgr = MyBase.BindingContext(SurveyDataSet, "survey")
fix for .net 3.5:



  • Now add the following code to the previous button

bindMgr.Position -= 1

  • Add this code to the Next button

bindMgr.Position += 1

  • Test it

simple data binding
You can make changes to the data in the textboxes and it changes the dataset, but it does not change the actual dataStore (your Access database)

  • Add another button and change the text to Update
  • Add the following code to it

MessageBox.Show("Database was updated")
Catch ex As Exception
MessageBox.Show("Problem updating database")
End Try

  • Try it by running the EXE file in your debug
  • Make sure you build it first so the EXE file is the latest version
  • Click the Build menu and select Build Solution

build solution
visual basic data binding