Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SqlDataAdapter.Update sometimes does not update

SqlDataAdapter.Update sometimes does not update

Scheduled Pinned Locked Moved Database
helpdatabasequestionannouncement
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    james cxx
    wrote on last edited by
    #1

    As the subject suggests, I'm simply updating the database with SqlDataAdapter.Update and sometimes no update occurs, but usually it does. If it never worked, I'd know it was a problem with my code, but running twice the same steps doesn't always produce the same results. I've read on the web that others have seen this behavior but haven't seen any fix or workaround. Anyone here experienced this or know a workaround? -- James --

    J 1 Reply Last reply
    0
    • J james cxx

      As the subject suggests, I'm simply updating the database with SqlDataAdapter.Update and sometimes no update occurs, but usually it does. If it never worked, I'd know it was a problem with my code, but running twice the same steps doesn't always produce the same results. I've read on the web that others have seen this behavior but haven't seen any fix or workaround. Anyone here experienced this or know a workaround? -- James --

      J Offline
      J Offline
      james cxx
      wrote on last edited by
      #2

      So I'm happy to report the problem was with my code and not with the .NET SqlDataAdapter. But I think the circumstances of the problem bear repeating so that others might avoid it. Form A creates some SqlDataAdapters that fill a dataset and periodically refreshes it. At some point, due to user interaction, an instance of "Form B" is created and passed a reference to the SqlDataAdapters. Form B then finds a DataRow in one of the tables of the dataset, does some work on it, and then calls SqlDataAdapter.Update to put the changed DataRow in the database. And this worked _most_ of the time, but occasionally it would not - no data would be updated to the database. It turns out that during Form A's periodic update, it would clear the datatable and the refill it. This process would cause Form B's datarow it was working on to get to a state of DataRowState.Detached. Since the DataRow was now detached, when form B would call SqlDataAdapter.Update, the info from the row would not go to the database because the DataRow is not associated with the DataSet that the adapter was working with. And there was no error to be reported in this circumstance. So the moral of the story is this: Beware what's happening to your DataSet or DataTables while working with a DataRow. And it doesn't hurt to make sure the row hasn't somehow become detatched when you weren't watching. -- James --

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups