Can't save new records to the dataset - I'm practising with the binary formatter
-
I’m practicing a database and I have a 3-column table. I’m using binary formatting to save/open the file. I can’t see what is wrong with my code – I can display records in the datagrid view ok when I press the save button I can also save the records into the dataset ok when the save/close button is pressed. When I reopen the programme and press the reload button to reload the dataset, additional records will not be displayed nor saved though original records will be showing in the datagrid. When I reopen the programme and DO NOT press the reload button, I can enter new records and they will be saved because this is basically overwrites the original dataset. Ideally, I want to be able to open the dataset and then be able to add new records to the dataset/datatable. Any help and advice on how to correct this? Thanks, Steve Here is my code: Imports System.IO Imports System.Runtime.Serialization Imports System.Runtime.Serialization.Formatters.Binary Public Class Frm_DataEntry Dim ThePoint As New Point(540, 150) Public TheRecord As DataRow Dim ii As Integer Private Sub Frm_DataEntry_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Location = ThePoint End Sub Private Sub Tbx01_FirstName_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tbx01_FirstName.Enter Tbx01_FirstName.Clear() Tbx02_LastName.Clear() Tbx03_Phone.Clear() End Sub Private Sub Btn01_Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn01_Save.Click TheRecord = Frm_Mainform.dt_Table.NewRow TheRecord(Frm_Mainform.dt_Col02_FirstName) = Tbx01_FirstName.Text TheRecord(Frm_Mainform.dt_Col03_LastName) = Tbx02_LastName.Text Frm_Mainform.dt_Table.Rows.Add(TheRecord) Frm01_WithDGV.DGV01.DataSource = Frm_Mainform.ds_Dataset Frm01_WithDGV.DGV01.DataMember = Frm_Mainform.dt_Table.ToString Frm01_WithDGV.DGV01_BS_Col01_PKey.DataPropertyName = Frm_Mainform.dt_Col01_PKey.ToString Frm01_WithDGV.DGV01_BS_Col02_FirstName.DataPropertyName = Frm_Mainform.dt_Col02_FirstName.ToString Frm01_WithDGV.DGV01_BS_Col03_LastName.DataPropertyName = Frm_Mainform.dt_Col03_LastName.ToString Dim ii As Integer ii = Frm_Mainform.dt_Table.Rows.Count MessageBox.Show(ii) End Sub Private Sub Btn02_SaveAndClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn02_SaveAndClose.Click