Public Class frmCities

  Private Sub frmCities_Load(ByVal sender As System.Object,
                             ByVal e As System.EventArgs) Handles MyBase.Load
    Me.CitiesTableAdapter.Fill(Me.MegacitiesDataSet.Cities)
    NameTextBox.SelectionStart = 0
  End Sub

  Private Sub btnUpdate_Click(ByVal sender As System.Object,
                              ByVal e As System.EventArgs) Handles btnUpdate.Click
    'These two lines update the database file on the hard drive.
    BindingSource1.EndEdit()
    CitiesTableAdapter.Update(MegacitiesDataSet.Cities)
  End Sub

  Private Sub btnSearch_Click(ByVal sender As System.Object,
                              ByVal e As System.EventArgs) Handles btnSearch.Click
    Dim currentCity As String = NameTextBox.Text
    If txtCity.Text <> "" Then
      BindingSource1.Position = BindingSource1.Find("name", txtCity.Text)
      If NameTextBox.Text <> txtCity.Text Then
        MessageBox.Show("City not found.")
        BindingSource1.Position = BindingSource1.Find("name", currentCity)
      End If
    Else
      MessageBox.Show("You must enter the name of a city.")
    End If
  End Sub

End Class
