Results 1 to 2 of 2

Thread: Database saving and then un-saving when program restarts?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2021
    Posts
    29

    Database saving and then un-saving when program restarts?

    I can add, delete, and save/update perfectly, through the program and the changes I have made will appear on the database in the program. If I go into the Microsoft access file, the changes will be there saved, and even after I close the program the changes remain in the Microsoft access file. But if I open up my program again then the changes I have made will get deleted in both the program and the Microsoft access file and it's left me clueless.

    Original: https://prnt.sc/ww7rsl
    Original in Microsoft Access file: https://prnt.sc/ww7w27

    Added a new Record: https://prnt.sc/ww8dex
    New record saved to Microsoft Access file: https://prnt.sc/ww8gff

    But if I restart the program the database goes back to how it was at first, same with the Microsoft Access File
    https://prnt.sc/ww8mjt

    Code:
    Option Explicit On
    Option Strict Off
    
    Public Class ManagePodBookings
        Private Sub ManagePodBookings_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'Loads the Pod Booking Database
            RefreshData()
            Me.PodBookingsTableAdapter.Fill(Me.PodBookingsDataSet.PodBookings)
        End Sub
    
        Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
            'Shows the staff form
            Staff.Show()
            Me.Hide()
        End Sub
    
        Private Sub btnMainMenu_Click(sender As Object, e As EventArgs) Handles btnMainMenu.Click
            'shows the main menu
            MainMenu.Show()
            Me.Hide()
        End Sub
    
        Private Sub PodComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles PodComboBox.SelectedIndexChanged
            'Making it so users cannot edit ComboBox values
            PodComboBox.DropDownStyle = ComboBoxStyle.DropDownList
        End Sub
        'Making it so users cannot edit ComboBox values
    
        Private Sub RefreshData()
    
            'Refreshing the table data
            Try
                Me.PodBookingsBindingSource.Filter = Nothing
                Me.PodBookingsTableAdapter.Fill(Me.PodBookingsDataSet.PodBookings)
            Catch ex As Exception
                MsgBox("There was an error refreshing the data.")
            End Try
        End Sub
    
        Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
            'Adds a New Record within the Data Table.
            Try
                With btnAdd
                    If .Text = "Add New Record" Then
                        PodBookingsBindingSource.AddNew()
                        PeopleNumericUpDown.Value = 0
                        ArrivalDateDateTimePicker.Value = Now.Date
                        DepartureDateDateTimePicker.Value = Now.Date
                        .Text = "Cancel New Record"
                    Else
                        RefreshData()
                        .Text = "Add New Record"
                    End If
                End With
    
            Catch ex As Exception
                MsgBox("There was an error adding a new record." & ex.Message.ToString(),
                       MsgBoxStyle.OkOnly Or MsgBoxStyle.Information)
            End Try
    
        End Sub
    
        Private Sub Save_Click(sender As Object, e As EventArgs) Handles btnSave.Click
            'Handles the save button
            Try
    
                Dim result As DialogResult
                result = MessageBox.Show("Do you want to save the selected record?",
                               "Glorious Getaways", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    
                If (result = DialogResult.Yes) Then
                    Validate()
                    PodBookingsBindingSource.EndEdit()
                    TableAdapterManager.UpdateAll(Me.PodBookingsDataSet)
    
                    MessageBox.Show("The record has been saved successfully.",
                                "Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Information)
    
                    RefreshData()
    
                    btnAdd.Text = "Add New Record"
    
                Else
    
                    Return
                End If
    
            Catch ex As Exception
                MessageBox.Show("There was an error Saving the Data." & ex.Message.ToString(),
                                "Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
    
        Private Sub Delete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
            'Deletes a record from the Data Table
            Try
                If MessageBox.Show("Do you want to permanently delete the selected record?",
                                   "Glorious Getaways", MessageBoxButtons.YesNo,
                                   MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) =
                                   Windows.Forms.DialogResult.Yes Then
                    PodBookingsBindingSource.RemoveCurrent()
    
                    PodBookingsBindingSource.EndEdit()
                    PodBookingsTableAdapter.Update(PodBookingsDataSet.PodBookings)
    
                    RefreshData()
    
                    MessageBox.Show("The record has been deleted sucessfully.",
                                "Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Else
                    Return ' Exit Sub
                End If
            Catch ex As Exception
                MessageBox.Show("There was an error deleting the Data." & ex.Message.ToString(),
                                "Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
    
        Private Sub SearchWarning()
            'Disabling search whilst adding new record.
            MsgBox("You are unable to Search whilst adding a new Record.",
                   MsgBoxStyle.OkOnly Or MsgBoxStyle.Exclamation,
                   "Glorious Getaways")
        End Sub
    
        Private Sub SearchBox_Click(sender As Object, e As EventArgs) Handles Search.Click, btnSearch.Click
            'Disabling search whilst adding new record.
            If btnAdd.Text = "Cancel New Record" Then
                SearchWarning()
                Exit Sub
            End If
        End Sub
    
    
        Private Sub SearchButton_Click(search As Object, e As EventArgs) Handles btnSearch.Click
            If PodBookingsBindingSource.Count < 1 Then
                MsgBox("The search item was not found.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
                           "Glorious Getaways")
    
                RefreshData()
            End If
    
    
            Try
            Catch ex As Exception
                MessageBox.Show("There was an error when Searching." & ex.Message.ToString(),
                                "Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
    
        Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs)
            Try
                Me.PodBookingsTableAdapter.FillBy(Me.PodBookingsDataSet.PodBookings)
            Catch ex As System.Exception
                System.Windows.Forms.MessageBox.Show(ex.Message)
            End Try
        End Sub
    End Class

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,339

    Re: Database saving and then un-saving when program restarts?

    Follow the first link in my signature below. It likely addresses your issue.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width