Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Can't add new records to reopened database

Can't add new records to reopened database

Scheduled Pinned Locked Moved .NET (Core and Framework)
questiondatabasejsonhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BluesEnd
    wrote on last edited by
    #1

    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 Dim Filename As String = "PermitToWork.pmt" Dim fStream As FileStream Frm01_WithDGV.DGV01.DataSource = Frm_Mainform.ds_Dataset Frm01_WithDGV.DGV01.DataMember = Frm_

    H 1 Reply Last reply
    0
    • B BluesEnd

      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 Dim Filename As String = "PermitToWork.pmt" Dim fStream As FileStream Frm01_WithDGV.DGV01.DataSource = Frm_Mainform.ds_Dataset Frm01_WithDGV.DGV01.DataMember = Frm_

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      One possible reason that your question has not been answered is that it is too difficult to read your code sample. If you place it between pre tags and format it properly you will have more chance of getting an answer. <pre> put your code here and indent it properly </pre>

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups