none
DataSet Not Displaying Add/Update/Delete from Form

    Question

  • I'm using Microsoft Visual Studio 2008 to create an application (.VB).  The application connects to a Microsoft Access 2007 database.  When the user starts the application, the application pulls in the data from the database via the "TableAdapter.Fill" method.  The user can then add/update/delete records in the form and those changes are saved and confirmed in the database.  The problem is when the user close completely out of the application and restarts it, the modifications that were made and originally sent/saved to the database are wiped/deleted.  It appears that the dataset in the application never saves the modifications and when the program restarts it uses the data that was originally loaded into it during the design/build phase of the application.  Is there anyone that can help explain to me what I am doing wrong?  Below are some lines of code from the program:

    Imports System
    Imports System.Data
    Imports System.Data.SqlClient

    Public Class frmStudent_File

        Private Sub frmStudent_File_New_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'DataSet1.Clear()
            'TODO: This line of code loads data into the 'DataSet1.Student_Info' table. You can move, or remove it, as needed.
            Me.Student_InfoTableAdapter.Fill(Me.DataSet1.Student_Info)
            'TODO: This line of code loads data into the 'DataSet1.Student_Status' table. You can move, or remove it, as needed.
            Me.Student_StatusTableAdapter.Fill(Me.DataSet1.Student_Status)
    .....

     Private Sub Student_InfoBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Student_InfoBindingNavigatorSaveItem.Click
            Try
                Me.Validate()

                '"EndEdit" - saves edits from the application
                Me.Student_InfoBindingSource.EndEdit()
                Me.Student_AddressesBindingSource.EndEdit()
                Me.Student_NotesBindingSource.EndEdit()
                Me.Student_StatusBindingSource.EndEdit()
                Me.Student_Graduation_InfoBindingSource.EndEdit()
                Me.Student_DemographicsBindingSource.EndEdit()
                Me.Student_Contact_InfoBindingSource.EndEdit()
                Me.Student_AdvisorBindingSource.EndEdit()
                Me.Applicant_Degree_ProgramBindingSource.EndEdit()
                Me.Applicant_Instructor_CommentsBindingSource.EndEdit()
                Me.Applicant_Letters_of_RecommendationBindingSource.EndEdit()
                Me.Applicant_PackagesBindingSource.EndEdit()
                Me.Applicant_ScoresBindingSource.EndEdit()
                Me.Applicant_StatusBindingSource.EndEdit()
                Me.Applicant_TranscriptsBindingSource.EndEdit()

                '"Update" - pushes the saved edits to the database
                Me.Student_InfoTableAdapter.Update(Me.DataSet1.Student_Info)
                Me.Student_AddressesTableAdapter.Update(Me.DataSet1.Student_Addresses)
                Me.Student_NotesTableAdapter.Update(Me.DataSet1.Student_Notes)
                Me.Student_StatusTableAdapter.Update(Me.DataSet1.Student_Status)
                Me.Student_Graduation_InfoTableAdapter.Update(Me.DataSet1.Student_Graduation_Info)
                Me.Student_DemographicsTableAdapter.Update(Me.DataSet1.Student_Demographics)
                Me.Student_Contact_InfoTableAdapter.Update(Me.DataSet1.Student_Contact_Info)
                Me.Applicant_Degree_ProgramTableAdapter.Update(Me.DataSet1.Applicant_Degree_Program)
                Me.Applicant_Instructor_CommentsTableAdapter.Update(Me.DataSet1.Applicant_Instructor_Comments)
                Me.Applicant_Letters_of_RecommendationTableAdapter.Update(Me.DataSet1.Applicant_Letters_of_Recommendation)
                Me.Applicant_PackagesTableAdapter.Update(Me.DataSet1.Applicant_Packages)
                Me.Applicant_ScoresTableAdapter.Update(Me.DataSet1.Applicant_Scores)
                Me.Applicant_StatusTableAdapter.Update(Me.DataSet1.Applicant_Status)
                Me.Applicant_TranscriptsTableAdapter.Update(Me.DataSet1.Applicant_Transcripts)
                Me.TableAdapterManager.UpdateAll(Me.DataSet1)
                'DataSet1.AcceptChanges()

                MessageBox.Show("Update Completed")

            Catch ex As Exception
                MessageBox.Show("Update Failed")
            End Try
    -------
    <connectionStrings>
            <add name="beta.My.MySettings.betaConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\beta.accdb"
                providerName="System.Data.OleDb" />
        </connectionStrings>


    When the save button on the navigation tool bar is clicked, the message "Update Complete" is displayed and a quick check of the Microsoft Access database shows the changes were made and saved to the database.  However, a quick Preview Data, does not show the changes, in neither the in Data Sources tab or the Server Explorer tab, from Microsoft Visual Studio.  


    Any help/suggestions would be greatly appreciated.

    Very Respectfully,
    David

    Wednesday, February 17, 2010 1:50 PM

Answers

  • David,

    i don't know how you have the app setup but it sounds like a common issue with the way the database is handled by default.  there are two database files that are being worked with here.  in the designer or IDE you work with the database in the main application folder.  when you debug the database is copied to the debug directory.  this can be changed using the database file -  copy to output directory - setting.  it most likely is set to copy always, this will copy over the database in the debug directory every time and so you lose any changes.  do not copy or never copy (forgot the name) will not copy at all.  copy if newer will only copy if the file is a newer version such as if you make a change to it.

    typically you might use copy if newer but you may want to go without copying it over and work directly with a file in a set directory for testing.  you would need to adjust your connection string for this for testing and then set it back when ready to deploy the application.

    it can be confusing with the default at times because you make changes in the designer to one file and then you run and it copies over what you changed using your application.  so you start to think that your application does not work.  this is such an awkward annoying thing but as far a i know it was intended to help you deploy a clean database file with your finished application.
    FREE
    DEVELOPER TOOLS     CODE     PROJECTS

    DATABASE CODE GENERATOR
    DATABASE / GENERAL  APPLICATION TUTORIAL
    Upload Projects to share or get help on and post the generated links here in the forum
    www.srsoft.us
    Wednesday, February 17, 2010 2:13 PM

All replies

  • David,

    i don't know how you have the app setup but it sounds like a common issue with the way the database is handled by default.  there are two database files that are being worked with here.  in the designer or IDE you work with the database in the main application folder.  when you debug the database is copied to the debug directory.  this can be changed using the database file -  copy to output directory - setting.  it most likely is set to copy always, this will copy over the database in the debug directory every time and so you lose any changes.  do not copy or never copy (forgot the name) will not copy at all.  copy if newer will only copy if the file is a newer version such as if you make a change to it.

    typically you might use copy if newer but you may want to go without copying it over and work directly with a file in a set directory for testing.  you would need to adjust your connection string for this for testing and then set it back when ready to deploy the application.

    it can be confusing with the default at times because you make changes in the designer to one file and then you run and it copies over what you changed using your application.  so you start to think that your application does not work.  this is such an awkward annoying thing but as far a i know it was intended to help you deploy a clean database file with your finished application.
    FREE
    DEVELOPER TOOLS     CODE     PROJECTS

    DATABASE CODE GENERATOR
    DATABASE / GENERAL  APPLICATION TUTORIAL
    Upload Projects to share or get help on and post the generated links here in the forum
    www.srsoft.us
    Wednesday, February 17, 2010 2:13 PM
  • Thanks.  My program seems to be working (today).  I was able to change the path for the database in the Server Explore to point to the actual database in the bin/debug folder, eventhough the dataset still points to the parent folder of the bin/debug folders.  But, it works for now.  I wasn't able to figure out the Copy   Again, thank you.

    Very Respectfully,
    David
    Thursday, February 18, 2010 3:34 PM
  • David,

    something else you can do is:

    leave your connection as is
    run or build the application one time
    then set the copy to output directory setting to "do not copy" by right clicking on the database file and click properties

    then when you need to run the program just use the build option from the project menu (i believe).  now the project will build any changes you have made and you can go directly to the bin/debug folder of the application and run it from there.

    the only thing you need to be careful about with this is you will not be debugging, so it will not hit any breakpoints, etc...


    another thing to make it simple sometimes is to just create a little subroutine to place test data into database on each buiild.  but, copy if newer still is an easy option if you still need to make changes to the database while testing.

    i know all this can be confusing, you just have to play with it and get a feel for what all is happening.

    when i work with sql server express i might just use sql server management studio express to create and change the database.  i leave it attached to the server software and point my connection string there.  makes it a little easier sometimes for me.

    well, hope this helps and does not add any more confusion.
    FREE
    DEVELOPER TOOLS     CODE     PROJECTS

    DATABASE CODE GENERATOR
    DATABASE / GENERAL  APPLICATION TUTORIAL
    Upload Projects to share or get help on and post the generated links here in the forum
    www.srsoft.us
    Thursday, February 18, 2010 7:56 PM