Visual Basic 2005 Express Edition Data Binding is not updating the database

Hi Microsoft Community,
I'm a new visual basic developer and am using the visual basic 2005 express edition with sql server 2005 express edition.  I've been going through some lessons and have encountered a situation that I'm hoping someone can identify what the issue is.

When creating a form with listbox and textbox components, I first request data from a table called customer.  I'm using a table adapter to manage the connection, request and response from my sql server express database called mycompany.  Upon the return of the data, my intermediate dataset is populated with the requested data.  I'm sure the data has been retrieved because by utiizing the binding navigator component, I can view the data. 

I have tried to make updates and then save or delete using the binding navigator but when closing out of the application and return none of the changes are actually saved.  Since the binding navigator did not work by itself, I also manually typed code to propogate the changes back to the database with the following source code:
  bindingsource1.endedit( )
  tableadapter1.update(dataset1.customer)

When making a change to the data displayed in the form, I'm also returning the number of changes that were made through the udpate method.  It is accurately returning the number of changes in a messagebox.  However, the changes are not actually updating because when I open the the form or database, it shows the old values.  Any suggestions

Thanks,
Anthony 


Answer this question

Visual Basic 2005 Express Edition Data Binding is not updating the database

  • Allen Cheng

    Thank you!!...I've been going round in circles and bouncing of walls trying to get this to work.
    Only to find out this is a debug issue and that VB itself has been over wirting the data...grrr!!

  • ShimpiSuhas

    Hi, i was also exploring the tutorial when i got the same error. It works, however I still do not know how to replace the origninal / imported database file with the altered database file from the bin. (am i correctly to assume that whenever the program closes it will not throw away the duplicated databasefile from the bin, given that the program does not overwrite it ; it is not a temporarily file which only exists during run time).

    To overcome the problem previously described, i also set the "copy to output directory"to "copy if newer". So can anybody please tell me the code for replacing original database file with the databasefile from the output directory (quote: "copying the file manually and vice versa"

    or am i (VB rooky) missing something

    regards,

    Tamar


  • Huybs Kris

    Wow. Sound's like you just found out you need to shift the car from park to drive to make it go forward.



  • Uziels

    Thanks,

    Finaly solved. I hade the same problem. There should be a message or a warning telling that the compiler using multiple databases or copies.



  • dean gross

    Much appreciated,

    I started to think I would need to buy a full version of Visual Studio 2005 - Quite expensive around here.

    It might have been a bit of a pain, But VB express 2005 is excellent, and it's free...


  • Siggy01

    Thank you for this! It only took me 2 days to finally try to look for this in the forum. I assumed it was something wrong with my machine configuration. You'd think they would update the tutorial or at least make mention of the mistake!
  • RibTickler

    Just want to add my name to the recall petition of whoever is responsible for having me waste 3 days trying to figure this out.
  • weirdbeardmt

    thank you

    it was usefull information


  • Pleb

    I had the same problem, and found an answer in another post to another (I think) forum.
    Visual Studio Express/VB Express actually maintains two copies of the database, one in the Project folder, and one in the bin folder. Each time the application is restarted the former is copied to the latter, so you get a clean copy. OK if that is what you want, but a pain otherwise.

    I am told this is a design/debug time problem - the deployed version works OK.

    You can change this behaviour by:
    a) telling the system NOT to copy the database from wherever it was initially when first creating the connection. However I gather this can give deployment issues to do with absolute references to the database (I have not got that far myself).
    b) There is a property you can set (I forget exactly where, since I am not at my own m/c to look) which controls whether this copying occurs or not. The only problem is that teh database designer works against the original copy in the Project folder, so if you turn copying off and then make any changes to the database structure you have to copy it into the bin folder yourself before they will be picked up.

    Not the best solution to the problem, and not the best documentation (it is in there but about three levels deep).

    Tony.

  • BFDS.BIZ

    hi,

    i too have a windows project developed in visual studio 2003. my datagrid works very well with visual studio 2003 but whne it comes to visual studio 2005 i am not able to bind the data with the controls. i have set the property of 'copy to output' and to not to copy. but even then i am not able to databind my controls. what do you exactly mean by the datafiles that you have asked to put it in the output folder. do you mean the datafiles to be the .mdf files.

    It would be great if someone could help me out with this. i am still a beginner.

    cheers



  • sharathkumarmv

    Thanks Tony!!!  I was able to find the posting I believe you were referring to (I copied below).  This is what I did to get it working.... To update the proptery, highlight the db in solution explorer > go to properties > change the "copy to output directory" property to "copy if newer". Now I can move on... thanks again.

    __________________

    Hi,

    This is a blog about working with Local Data File: https://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx. Quoting from this blog

    Where is my data -- Understanding the file copy for desktop projects

    One of the things to know when working with local database files is that they are treated as any other content files. For desktop projects, it means that by default, the database file will be copied to the output folder (aka bin) each time the project is built.

    It is possible that when you hit F5 again after saving the data, the Northwind.MDF file under bin was replaced with the original one and your change was lost. Would you please verify if this is the case and follow the work around in the blog to fix the issue

    1. If you select local database file in the Solution Explorer window, you will see a property called ‘Copy to Output’ in the Properties window. By default it is set to ‘Copy Always’ which means that on each build, the data files in the project folder will be copied to the output folder overwriting the existing data files if any. You can set this property to Copy Never and then manually put a copy of the data file in the output folder. This way, on subsequent builds, the project system will leave the datafile in the output folder and not try to overwrite it with the one from the project. The downside is that you still have two copies so after you modify the database file using the app, if you want to work on those changes in the project, you need to copy it to the project manually and vise-versa.

    2. You can leave the data file outside the project and create a connection to it in Database Explorer. When the IDE asks you to bring the file into the project, just say no. This way, both the design-time and the run-time will be using the same data file but the downside is that the path in the connection string will be hard coded and therefore it’ll be harder to share the project and deploy the app. Before deploying the app, just make sure to replace the full path in the settings with a relative path.

    Best regards,

     

  • Billy Feng

    WOW!!!

    Someone should be fired for this. You cannot imagine how long I have spent tryingt to get data updating to work... only to now find out that it was working all along, and that the development environment was overwriting my database. This is tottaly unacceptable! There is no indication anywhere that this database copying is occuring and it seems to the user like the database is not updating. The waste of time and money makes me sick. ARGGHHH!

    -Anton


  • gradley

    Yeah, except the analagous situation would be that the gears were randomly arranged so it's not immediately obvious where "park" and "drive" are!


  • Robert Flaming

    I have encountered the exact same problem. It appears that when the change is saved and you re-enter the application, you don't see it. I think the problem has to do with the fact that at form load the data adapter fills the dataset from the physical dataset. That tells me that the changes are not making it from the dataset to the actual database. How does this happen
  • Visual Basic 2005 Express Edition Data Binding is not updating the database