Imports System.Data.OleDb
Imports System.Data
Public Class CompanyDetails
    Dim DetailsConnection As OleDbConnection
    Dim DetailsCommand As OleDbCommand
    Dim DetailsAdapter As OleDbDataAdapter
    Dim DetailsTable As New DataTable
    Dim DetailsManager As CurrencyManager
    Private Sub CompanyDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'connect to details database
        DetailsConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Details.mdb")
        DetailsConnection.Open()
        'establish details command object
        DetailsCommand = New OleDbCommand("SELECT * FROM Details ORDER BY AnimationBar", DetailsConnection)
        'establish details data adapter/data table
        DetailsAdapter = New OleDbDataAdapter()
        DetailsAdapter.SelectCommand = DetailsCommand
        DetailsTable = New DataTable()
        DetailsAdapter.Fill(DetailsTable)
        'bind controls
        AnimationBar.DataBindings.Add("Text", DetailsTable, "AnimationBar")
        CompanyName.DataBindings.Add("Text", DetailsTable, "CompanyName")
        Addresse.DataBindings.Add("Text", DetailsTable, "Addresse")
        Tele.DataBindings.Add("Text", DetailsTable, "Tele")

        CustomerMessage.DataBindings.Add("Text", DetailsTable, "CustomerMessage")
        CustomerCare.DataBindings.Add("Text", DetailsTable, "CustomerCare")


        'establish currency manager
        DetailsManager = DirectCast(Me.BindingContext(DetailsTable), CurrencyManager)


    End Sub

    Private Sub CmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdOk.Click
        Dim SavedItem As String = AnimationBar.Text
        Dim SavedRow As Integer
        DetailsManager.EndCurrentEdit()
        DetailsTable.DefaultView.Sort = "AnimationBar"
        SavedRow = DetailsTable.DefaultView.Find(SavedItem)
        DetailsManager.Position = SavedRow
        Try
            'save the update details table
            Dim DetailsAdapterCommands As New OleDbCommandBuilder(DetailsAdapter)
            DetailsAdapter.Update(DetailsTable)
            MsgBox("Details has been changed", MsgBoxStyle.Information)
            Me.Hide()
            ATarification.Show()

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error Saving Database", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        'close the connection
        'dispose of the objects
        DetailsCommand.Dispose()
        DetailsAdapter.Dispose()
        DetailsTable.Dispose()
    End Sub

    Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCancel.Click
        ATarification.Show()
        Me.Hide()


    End Sub

 

 

End Class