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

- Select the database icon and click Next


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

- Choose Microsoft Access
- Click OK

- Click Browse to find your database file



- 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

- 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.
- Your project folder
- 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

- Set the DataSource by clicking the dropdown arrow and expanding the nodes until you get to your 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


- 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:
bindMgr=MyBase.BindingContext(Me.SurveyBindingSource)

- Now add the following code to the previous button
bindMgr.Position -= 1
- Add this code to the Next button
bindMgr.Position += 1

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
Try
Me.BindingSource1.EndEdit()
Me.SurveyTableAdapter.Update(Me.SurveyDataSet.Survey)
MessageBox.Show("Database was updated")
Me.SurveyTableAdapter.Fill(Me.SurveyDataSet.Survey)
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
