Results 1 to 5 of 5

Thread: Data does not persist in one table

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    220

    Data does not persist in one table

    Something strange, to me at least, is happening here. I embedded a database with few tables. When I write data to the tables it persists in others but it always disappears in one table. What can cause this? The database Build Action is set to 'Content' and the Copy to Output Directory is set to 'Copy if newer'. I am not sure what code I can send you. Thanks for helping.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Data does not persist in one table

    Data doesn't just disappear spontaneously. Either it was never there in the first place or you're deleting it, either by removing it from the database or replacing the database. Which of those three is happening in your case is impossible to say because we have no idea what you're actually doing. A diagnosis of the issue would require psychic power on our part.

    The fact that you're using Copy If Newer suggests that it's not the case that the database is being overwritten with a new copy but that's not guaranteed. The thing is, if it was the case then all changes that you saved would disappear, so it's easy to test. Simply save changes to multiple tables and see if any changes persist. If they do then the database has not been overwritten.

    The first thing to do is to check whether the changes are being saved at all. If you're calling Update on a data adapter or ExecuteNonQuery on a command then that call will return a number. If that number is not zero then that means that changes are being saved.

    I've seen plenty of instances of people writing code to save changes within a Try block and then having an empty Catch block, meaning that they wouldn't know even if the save was failing. For all we know, that's what you're doing. Test your code properly and, if the problem persists, post the relevant code here so we don't have to guess what it looks like.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    220

    Thumbs down Re: Data does not persist in one table

    Yes, you are right. The data kept on piling in the table. What is happening is that in the other tables I can write,update and read daata but in this one table I can only write data. I did not set permissions for each table. So I don't know where to change settings for this table so that I can also read, update and write data like in the others. Please help.

    Quote Originally Posted by jmcilhinney View Post
    Data doesn't just disappear spontaneously. Either it was never there in the first place or you're deleting it, either by removing it from the database or replacing the database. Which of those three is happening in your case is impossible to say because we have no idea what you're actually doing. A diagnosis of the issue would require psychic power on our part.

    The fact that you're using Copy If Newer suggests that it's not the case that the database is being overwritten with a new copy but that's not guaranteed. The thing is, if it was the case then all changes that you saved would disappear, so it's easy to test. Simply save changes to multiple tables and see if any changes persist. If they do then the database has not been overwritten.

    The first thing to do is to check whether the changes are being saved at all. If you're calling Update on a data adapter or ExecuteNonQuery on a command then that call will return a number. If that number is not zero then that means that changes are being saved.

    I've seen plenty of instances of people writing code to save changes within a Try block and then having an empty Catch block, meaning that they wouldn't know even if the save was failing. For all we know, that's what you're doing. Test your code properly and, if the problem persists, post the relevant code here so we don't have to guess what it looks like.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Data does not persist in one table

    Again, show us the code and tell us what happened. People post here all the time and tell us what they think is happening, only for the reality to be something else. You say that you can only write data to this table, presumably meaning insert new records, but not update or read data. Show us the code that is trying to update and read and tell us what happens when you execute it. If what you say is true then an exception would be thrown when that code is executed. If that's the case then there would be an error message. Why don't we already know what that error message is? You need to provide ALL the RELEVANT information. If an error occurs then obviously the error message is relevant.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    220

    Re: Data does not persist in one table

    I have located an error. It had nothing to do with the database. I had forgotten to update a select statement condition. I feel very silly as always. Thanks for attempting to help, jmc et al.

    Quote Originally Posted by jmcilhinney View Post
    Again, show us the code and tell us what happened. People post here all the time and tell us what they think is happening, only for the reality to be something else. You say that you can only write data to this table, presumably meaning insert new records, but not update or read data. Show us the code that is trying to update and read and tell us what happens when you execute it. If what you say is true then an exception would be thrown when that code is executed. If that's the case then there would be an error message. Why don't we already know what that error message is? You need to provide ALL the RELEVANT information. If an error occurs then obviously the error message is relevant.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width