locked
Losing data in a datatable RRS feed

  • Question

  • Hello Everyone

    I have a small issue I've created an application which you add people or contact's into a database. But the issue is when you close the application (once installed via .MSI) all the information disappears from the database. i been looking at this for a while and i can't get my head around the problem. Does anyone have any ideas?

    If you need anymore coding please ask 

    Button to add Information into the Database( this is on a different form)

     Dim newrow As DataRow = Form1.ContactsDatabaseDataSet.DataTable1.NewRow
        Dim dataupdate = Form1.ContactsDatabaseDataSet.DataTable1
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Try
                Dim dr = Form1.ContactsDatabaseDataSet.DataTable1.NewDataTable1Row
                With dr
                    .First_Name_ = TextBox1.Text
                    .Second_Name_ = TextBox2.Text
                    ._House_No_Name_ = TextBox3.Text
                    .Address_1_ = TextBox4.Text
                    .Address_2_ = TextBox5.Text
                    .Address_3 = TextBox6.Text
                    .County_ = ComboBox1.Text
                    .Post_Code_ = TextBox7.Text & "" & TextBox8.Text
                    .Position_ = TextBox9.Text
                    .Company_ = ComboBox2.Text
                    .Branch_ = TextBox10.Text
                    .Phone_No_ = TextBox11.Text & "" & TextBox12.Text
                    .Mobile_No_ = TextBox13.Text
                    ._E_Mail_ = TextBox14.Text
                    .Table.Rows.Add(dr)
                    cleartextboxs()
                     Me.DataTable1TableAdapter.Update(ContactsDatabaseDataSet.DataTable1)
                End With
                If TextBox11.Enabled And TextBox12.Enabled AndAlso TextBox13.Enabled = False Then
                    TextBox11.Enabled = True
                    TextBox12.Enabled = True
                    TextBox13.Enabled = True
                Else
                    TextBox11.Enabled = True
                    TextBox12.Enabled = True
                    TextBox13.Enabled = True

                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub

     Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'ContactsDatabaseDataSet.DataTable1' table. You can move, or remove it, as needed.
            Me.DataTable1TableAdapter.Fill(Me.ContactsDatabaseDataSet.DataTable1)

        End Sub

    Form1 

      Private Sub DataTable1BindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs)
            Me.Validate()
            Me.DataTable1BindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.ContactsDatabaseDataSet)
        End Sub

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'ContactsDatabaseDataSet.DataTable1' table. You can move, or remove it, as needed.
            Me.DataTable1TableAdapter.Fill(Me.ContactsDatabaseDataSet.DataTable1)
            DataTable1DataGridView.RowHeadersVisible = False
        End Sub

    Wednesday, July 17, 2013 5:51 PM

Answers

  • Hello 

    sorry i took so long to reply I've been working the file extension is .accdb.

    sorry i think I've solved the problem i think i'm using a temp file when i added a new data-set to the project at the start when i was creating the application. But thank's for your help and i will leave a message again if it doesn't help 

    Many Thanks Again

    • Marked as answer by Youen Zen Friday, July 26, 2013 9:12 AM
    Thursday, July 18, 2013 6:34 PM

All replies

  • Where is the data being stored back into the database.  I see the update of the DataTable and the Form Control, but not back to the database.

    You need to have write privieledges to the database and if the database is shared it may not allow you to write when another user is accessing the database.  This depends on the type of database you are using and the credentials.


    jdweng

    Wednesday, July 17, 2013 6:08 PM
  • Hello

    the database is stored in the Bin\Debug when I created the program and I put it in with the Application folder with Visual Studio 2010 (when making the install). I have the all privieledges that I need I created the File and table in a different project.

    the Database is set in a form1 and the project have no network link, it's a standalone project

    If you need to ask anything else just ask

      

    Wednesday, July 17, 2013 6:22 PM
  • The time stamp of the database file should change when a write occurs.  What is the extension of the database file?  I don't see any writes to the database.  What instruction do are you using to perform the write? (not the datatable or the the form control).  You may need to close the database connection for the databae to actually get updated.

    jdweng

    Wednesday, July 17, 2013 9:38 PM
  • Hello 

    sorry i took so long to reply I've been working the file extension is .accdb.

    sorry i think I've solved the problem i think i'm using a temp file when i added a new data-set to the project at the start when i was creating the application. But thank's for your help and i will leave a message again if it doesn't help 

    Many Thanks Again

    • Marked as answer by Youen Zen Friday, July 26, 2013 9:12 AM
    Thursday, July 18, 2013 6:34 PM