Imports System.Data.OleDb

 

Public Class Form1

    Dim objBS As New BindingSource

    Dim objDA As New OleDbDataAdapter

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        LoadBindingSource("Select * From Snippets", objDA, objBS)

 

  TextBox1.DataBindings.Clear()

        TextBox1.DataBindings.Add("Text", objBS, "Description")

 

        TextBox1.Enabled = True

        cmdPrevious.Enabled = True

        cmdNext.Enabled = True

        cmdUpdate.Enabled = True

 

 

 

    End Sub

 

 

    Public Sub LoadBindingSource(ByVal selectCommand As String, ByRef da As OleDbDataAdapter, ByRef bs As BindingSource)

 

        Try

 

            Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Snippets.mdb"

 

            ' Create a new data adapter based on the specified query.

            da = New OleDbDataAdapter(selectCommand, ConnectionString)

 

            ' Create a command builder to generate SQL update, insert, and

            ' delete commands based on selectCommand. These are used to

            ' update the database.

            Dim commandBuilder As New OleDbCommandBuilder(da)

 

            ' Populate a new data table and bind it to the BindingSource.

            Dim table As New DataTable()

            table.Locale = System.Globalization.CultureInfo.InvariantCulture

            da.Fill(table)

            bs.DataSource = table

 

        Catch ex As OleDbException

            MessageBox.Show(ex.Message)

        End Try

 

    End Sub

 

    Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click

      objBS.MoveNext

    End Sub

 

    Private Sub cmdPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrevious.Click

        objBS.MovePrevious()

 

    End Sub

 

    Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click

        objBS.EndEdit()

        objDA.Update(CType(objBS.DataSource, DataTable))

        MsgBox("Database Updated.")

    End Sub

 

End Class