TableAdapter.Update does not save data

How can I save data entered in a dataset via the UI I tried the code suggested in the "VB Guided Tour",

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

Me.AddressesBindingSource.EndEdit()

Me.AddressesTableAdapter.Update(Me.SQLdbDataSet.Addresses)

End Sub

but all changes are lost when I restart the application.

Thanks.



Answer this question

TableAdapter.Update does not save data

  • bilbo08831

    Thanks! I thought there must be a setting somewhere that I was missing. I find that if I set the copy property to "do not copy" I get an unhandled exception whenever I try to open the dataset. But "copy if newer" works just fine. The only problem is remembering to copy from App\bin\debug to App when needed.
  • Bob The Hacker

  • Perrin1234

    Thanks. But I guess I'm too new to this to understand your suggestion. I added a line,

    AddressesTableAdapter.UpdateCommand = new SQLUpdateCommand

    just before the update, but that just generated two compiler errors:

    Error 1 'UpdateCommand' is not a member of 'VBdatabase.SQLdbDataSetTableAdapters.AddressesTableAdapter'. 

    Error 2 Type 'SQLUpdateCommand' is not defined. 

    What am I missing

    Thanks.

  • tehmann

    Found the solution in the free downloadable book 'Build a program now' at the 'Registration Benifit Program' p154 (text in blue).

    In brief there are 2 copies of the database: 1 in the application folder and 1 in the bin\debug folder. At design time the database in the app folder is used while at run time the other one.

    By default in the solution explorer the database is set to COPY ALWAYS to the bin\debug folder which means that the database is alwys overwritten by the one in the application folder.

    Solution:
    You can change this property to DO NOT COPY and copy it yourself if when needed or leave the database out of the project. When asked to bring it in the project when creating a connection, sympy say no.

    I hope you are as pleased as I am now to have found that annoyance.


  • paul9955

    Nice one, spent days scratching my head over this one, thanks

  • mbackxp

    can u plz explain what the command in UpdateCommand and how to make this cuz adressTableadapter.update has to return a value in int

    thanks

    I believe AddressesTableAdapter.Update invokes the AddressTableAdapter.UpdateCommand. Prior to calling Update you'll need to set AddressesTableAdapter.UpdateCommand = new SQLUpdateCommand...

    Hope this helps,

    Hal



  • AmA-Nique

    I'm having a similar issue wher the data is not updating. I don't have a local copy of the database at all. I'm connecting to a remotly hosting SQL Server 2005 database. Everything was working fine until yesterday and now it's as if the tables are all read-only. The TableAdapter.Update command never invokes the underlying Update method. The underlying update method that should be invoked is

    public virtual int Update(DataTable dataTable) {

    return this.Adapter.Update(dataTable);

    }

    I set a breakpoint on the code and it never hit! ANyone have a clue why this would be


  • Manu Evans

    I believe AddressesTableAdapter.Update invokes the AddressTableAdapter.UpdateCommand. Prior to calling Update you'll need to set AddressesTableAdapter.UpdateCommand = new SQLUpdateCommand...

    Hope this helps,
    Hal


  • helen put

    This definitely sounds like my problem. I hate to show my ignorance but can you tell me how I change these options

     

    Thanks,


  • DharmeshP

    Hi all !

    Man, forget all !!!

    If u using a bindindsource, verify your's components databindings. If they connected direct from dataset the updates not work. Bind using bindingsource object and done!

    Sorry my english!!!

    I hope helpful.


  • chester645

    I must have missed something in the documentation.  Everytime I would run this program The data would disappear.  Thanks for pointing out that there are two copies.

     

     


  • Timothy Wilson

    "Found the solution in the free downloadable book 'Build a program now' at the 'Registration Benifit Program' p154 (text in blue)."

    Where can I download this book I to am having problems with the TableAdapter. My problem is when I try to update it tells me that .update is not a member of my workbook.

    Thank you

    Tom



  • jmramirez

    Hi Guys, ran into the same problem last night and wasted 2 hours trying to figure out what was wrong.

    As was posted above, this issue can be fixed by clicking on the database in the solution explorer and adjusting the property to read 'Copy if Newer' instead of 'Copy Always'. If you set it to 'Do Not Copy', you need to manually copy it or you an exception saying that it can't find the database file.

    Thanks again to all who figured this out.

  • chadiswar

    I have the same problem in C# even if you don't use a tableAdapter but a sqlCommand object instead.  Though affectedRecords reflects the correct rows affected.



  • TableAdapter.Update does not save data