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. General Programming
  3. Visual Basic
  4. Updating database and using filewatcher

Updating database and using filewatcher

Scheduled Pinned Locked Moved Visual Basic
databasequestionannouncement
4 Posts 3 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.
  • C Offline
    C Offline
    Cory Kimble
    wrote on last edited by
    #1

    I am trying to fill a dataset and update a dataset to change values in a database. I have a third party program entering records in mydatabase. My program fills a dataset. I do some processes and update the dataset to update the mydatabase. All works well, until I factor in the fact that I want to watch the database and update a field when a record has a certain value so, I watch to see if any changes and Onchanged is called then I test the varables and if the record has a certain value I want to change a different value. But, then the Onchanged event is called again and I am in a endless loop of calling the method, changing the variable, calling the method, changing the variable. What would you suggest?

    N D 2 Replies Last reply
    0
    • C Cory Kimble

      I am trying to fill a dataset and update a dataset to change values in a database. I have a third party program entering records in mydatabase. My program fills a dataset. I do some processes and update the dataset to update the mydatabase. All works well, until I factor in the fact that I want to watch the database and update a field when a record has a certain value so, I watch to see if any changes and Onchanged is called then I test the varables and if the record has a certain value I want to change a different value. But, then the Onchanged event is called again and I am in a endless loop of calling the method, changing the variable, calling the method, changing the variable. What would you suggest?

      N Offline
      N Offline
      Naji El Kotob
      wrote on last edited by
      #2

      Hi, I am not sure if I understand your request clearly, but I think you need a query notification, did you try the SQLDependency class, it helps in refreshing the cached data when the original database changed. for more details please check this url http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx[^] hope this helps :)

      NajiCo http://www.InsideVB.NET[^] It's nice 2b important, but it's more important 2b nice...

      D 1 Reply Last reply
      0
      • N Naji El Kotob

        Hi, I am not sure if I understand your request clearly, but I think you need a query notification, did you try the SQLDependency class, it helps in refreshing the cached data when the original database changed. for more details please check this url http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx[^] hope this helps :)

        NajiCo http://www.InsideVB.NET[^] It's nice 2b important, but it's more important 2b nice...

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        That won't work on an Access database.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        1 Reply Last reply
        0
        • C Cory Kimble

          I am trying to fill a dataset and update a dataset to change values in a database. I have a third party program entering records in mydatabase. My program fills a dataset. I do some processes and update the dataset to update the mydatabase. All works well, until I factor in the fact that I want to watch the database and update a field when a record has a certain value so, I watch to see if any changes and Onchanged is called then I test the varables and if the record has a certain value I want to change a different value. But, then the Onchanged event is called again and I am in a endless loop of calling the method, changing the variable, calling the method, changing the variable. What would you suggest?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          There's no reliable way to do this in Access. Access doesn't support triggers, so your kind of screwed. You could use the FileSystemWatcher, but there's a problem with this. In order to get this to work, your Changed event would have to set a flag when it see's a change made and need to make its own change. This flag would tell the Changed event that it should ignore the event when it gets called again and then reset the flag.

          Private Sub ChangeEvent(blah, blah) Handles ....
          Static updatingDatabase As Boolean = False

          ' A change to the database has been detected.
          ' Check the flag to see if WE made the change, or if an outside
          ' source made the change.
          If updatingDatabase Then
              ' We're making the change.  Reset the flag
              ' and do nothing.
              updatingDatabase = False
          Else
              ' An outside source made the change.
              ' Set the flag and make our changes to the database.
              updatingDatabase = True
              ' Do you database update here.
          End If
          

          End Sub

          Now, there is a large problem with this. If the outside source makes a change to the database while this code is running, you can't tell the different between your code making the change and the outside source making the change. It's entirely possible that the outside source changes the database and your code will never see it. There is simply no way to do this reliably in Access. SQL Server, even the FREE Express Edition, support Triggers, that will easily allow you to do this in the SQL code of your database.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          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