none
lookup table does not save RRS feed

  • Question

  • Hi all,

     

    I have two table, Booking and Tariff, as following:

    Booking:                                                                         Tariff:

    b_no                                                                               t_season_no

    b_property_no                                                                 t_season_name

    b_guest_no                                                                     t_start_date

    b_arrival_date                                                                 t_end_date

    b_departure_date

    b_tariff

     

    there is a relationship between these two table ( t_season_no, b_tariff). However, in the Booking form, I established a lookup table to display the t_season_name instead of the t_season_no, and it is working, but when I want to save the record it save all the fields of the Booking table without the b_tariff. Could please anyone help me. It is necessary.

     

    Thank You,   Ali 

     

    These all my code for the Booking form.

     

    Public Class frmBooking

    'module_level variable.

    Private adb_sunHolidaysDataSet As dbSunHolidaysDataSet

    Private aBookingTableAdapter As dbSunHolidaysDataSetTableAdapters.BookingTableAdapter

    Private WithEvents aBookingBindingSource As BindingSource

    Private addingBoolean As Boolean = False

    Private editingBoolean As Boolean = False

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Private Sub setNavigation(ByVal valueBoolean As Boolean)

    'set the enabled property of the navigation buttons.

    With Me

    .btnFirstRecord.Enabled = valueBoolean

    .btnLastRecord.Enabled = valueBoolean

    .btnNextRecord.Enabled = valueBoolean

    .btnPreviousRecord.Enabled = valueBoolean

    End With

    End Sub

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Private Sub setControlsReadOnly(ByVal valueBoolean As Boolean)

    'lock or unlock the controls.

    With Me

    .txtB_no.ReadOnly = valueBoolean

    .txtB_properity_no.ReadOnly = valueBoolean

    .txtB_guest_no.ReadOnly = valueBoolean

    End With

    End Sub

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Private Sub SetButtonsForEdit()

    'set up the buttons for an Add or Edit operations.

    With Me

    .btnAddSave.Text = "&Save"

    .btnDeleteCancel.Text = "&Cancel"

    .btnEdit.Enabled = False

    .btnExit.Enabled = False

    If .addingBoolean Then

    .lblToolStripStatus.Text = "Adding"

    Else

    .lblToolStripStatus.Text = "Editing"

    End If

    End With

    End Sub

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Private Sub resetButtonsAfterEdit()

    'reset the buttons after an Add or Edit operation.

    With Me

    .btnAddSave.Text = "&Add"

    .btnDeleteCancel.Text = "&Delete"

    .btnEdit.Enabled = True

    .btnExit.Enabled = True

    .lblToolStripStatus.Text = String.Empty

    End With

    End Sub

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Private Sub frmBooking_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'TODO: This line of code loads data into the 'DbSunHolidaysDataSet.Tariff' table. You can move, or remove it, as needed.

    Me.TariffTableAdapter.Fill(Me.DbSunHolidaysDataSet.Tariff)

    'TODO: This line of code loads data into the 'DbSunHolidaysDataSet.Booking' table. You can move, or remove it, as needed.

    Me.BookingTableAdapter.Fill(Me.DbSunHolidaysDataSet.Booking)

    'TODO: This line of code loads data into the 'DbSunHolidaysDataSet.Tariff' table. You can move, or remove it, as needed.

    Me.TariffTableAdapter.Fill(Me.DbSunHolidaysDataSet.Tariff)

    'TODO: This line of code loads data into the 'DbSunHolidaysDataSet.Booking' table. You can move, or remove it, as needed.

    Me.BookingTableAdapter.Fill(Me.DbSunHolidaysDataSet.Booking)

    With Me

    Try

    'set up the dataset and fill it.

    .adb_sunHolidaysDataSet = New dbSunHolidaysDataSet

    .aBookingTableAdapter = New dbSunHolidaysDataSetTableAdapters.BookingTableAdapter

    .aBookingTableAdapter.Fill(.adb_sunHolidaysDataSet.Booking)

    'set up the bindingSource.

    .aBookingBindingSource = New BindingSource

    With .aBookingBindingSource

    .DataSource = Me.adb_sunHolidaysDataSet

    .DataMember = "Booking"

    .MoveLast()

    .MoveFirst()

    End With

    'bind the controls

    .txtB_no.DataBindings.Add("text", _

    .aBookingBindingSource, "b_no")

    .txtB_properity_no.DataBindings.Add("text", _

    .aBookingBindingSource, "b_properity_no")

    .txtB_guest_no.DataBindings.Add("text", _

    .aBookingBindingSource, "b_guest_no")

    .dtpB_arrival_date.DataBindings.Add("text", _

    .aBookingBindingSource, "b_arrival_date")

    .dtpB_departure_date.DataBindings.Add("text", _

    .aBookingBindingSource, "b_departure_date")

    .cbxB_tariff.DataBindings.Add("text", .aBookingBindingSource, "b_tariff")

    Catch ex As Exception

    MessageBox.Show("Data Error: " & ex.Message)

    End Try

    End With

    End Sub

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Private Sub btnAddSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSave.Click

    With Me

    If .btnAddSave.Text = "&Add" Then

    With .aBookingBindingSource

    .EndEdit()

    .AddNew()

    End With

    .addingBoolean = True

    .txtB_properity_no.Focus()

    .setNavigation(False)

    .setControlsReadOnly(False)

    .SetButtonsForEdit()

    Else

    'save button clicked.

    Try

    .aBookingBindingSource.EndEdit()

    .aBookingTableAdapter.Update(adb_sunHolidaysDataSet.Booking)

    .lblToolStripStatus.Text = "Record Saved"

    .addingBoolean = False

    .editingBoolean = False

    .setNavigation(True)

    .setControlsReadOnly(True)

    .resetButtonsAfterEdit()

    MsgBox("Update successful")

    Catch ex As Exception

    MsgBox("Update failed")

    End Try

    End If

    End With

    End Sub

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Private Sub btnDeleteCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteCancel.Click

    'delete the current record after confirming or cancel an Add or Edit.

    Dim deleteDialogResult As DialogResult

    With Me

    Try

    If .btnDeleteCancel.Text = "&Delete" Then

    deleteDialogResult = MessageBox.Show("Delete this Record?", _

    "Confirm Delete", MessageBoxButtons.YesNo, _

    MessageBoxIcon.Question)

    If deleteDialogResult = Windows.Forms.DialogResult.Yes Then

    .aBookingBindingSource.RemoveCurrent()

    .aBookingTableAdapter.Update(.adb_sunHolidaysDataSet.Booking)

    .lblToolStripStatus.Text = "Record Deleted"

    End If

    Else

    'cancel button clicked.

    .aBookingBindingSource.CancelEdit()

    .addingBoolean = False

    .editingBoolean = False

    .setNavigation(True)

    .setControlsReadOnly(True)

    .resetButtonsAfterEdit()

    End If

    Catch ex As Exception

    Dim messageString As String

    messageString = "Unable to complete the Delete/Cancel operation: " _

    & ex.Message

    MessageBox.Show(messageString, "Delete/Cancel", _

    MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

    End Try

    End With

    End Sub

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click

    'allow editing to the current record.

    With Me

    .editingBoolean = True

    .setNavigation(False)

    .setControlsReadOnly(False)

    .SetButtonsForEdit()

    End With

    End Sub

     

     

     

     

     

    Thursday, October 30, 2008 8:28 AM