Public Class CarsDataTierClass
    'module level variables
    Private aCarSizeTableAdapter As CarsDataSetTableAdapters.CarSizeTableAdapter
    Private aVehicleTableAdapter As CarsDataSetTableAdapters.VehicleTableAdapter
    Private aCarSizetoVehicleRelation As DataRelation
    Private aCarsDataSet As CarsDataSet
    Public Sub New()
        Try
            With Me
                'instantiate the tableadapters and dataset
                .aCarSizeTableAdapter = New CarsDataSetTableAdapters.CarSizeTableAdapter
                .aVehicleTableAdapter = New CarsDataSetTableAdapters.VehicleTableAdapter
                .aCarsDataSet = New CarsDataSet
                .aCarSizetoVehicleRelation = .aCarsDataSet.Relations!CarSizeToVehiclesRelation
                'fill the dataset
                .aCarSizeTableAdapter.Fill(.aCarsDataSet.CarSize)
                .aVehicleTableAdapter.Fill(.aCarsDataSet.Vehicle)
            End With
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub
    Public Function GetDataSet() As CarsDataSet
        'return the data set
        Return aCarsDataSet

    End Function

    Public Sub UpdateDataSet(ByVal aDataSet As CarsDataSet)
        'save all updates to the original data source
        Try
            'Update child deletes

            If aDataSet.Vehicle.GetChanges(DataRowState.Deleted) IsNot Nothing Then
                'get changes for the deleted child rows only
                Dim vehicleDeleteDataTable As DataTable
                vehicleDeleteDataTable = aDataSet.Vehicle.GetChanges(DataRowState.Deleted)
                aVehicleTableAdapter.Update(vehicleDeleteDataTable)
            End If
            'update all parent rows, regardless
            If aDataSet.CarSize.GetChanges() IsNot Nothing Then
                aCarSizeTableAdapter.Update(aDataSet.CarSize)
            End If
            'update child adds and edit
            If aDataSet.Vehicle.GetChanges(DataRowState.Added + DataRowState.Modified) IsNot Nothing Then
                'get the changes for the added and changed child rows only
                Dim CarSizeAddDataTable As DataTable
                CarSizeAddDataTable = aDataSet.Vehicle.GetChanges(DataRowState.Added + DataRowState.Modified)
                Me.aVehicleTableAdapter.Update(CarSizeAddDataTable)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub
End Class
