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. C#
  4. Get only modified data at form exit

Get only modified data at form exit

Scheduled Pinned Locked Moved C#
databasequestion
9 Posts 5 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.
  • M Offline
    M Offline
    manchukuo
    wrote on last edited by
    #1

    Hi guys I have a form that has like 30 controls on them all of them have data that it loads to from a DB, is there a efficient way to only get the data or control that was modified? Thanks

    H D 2 Replies Last reply
    0
    • M manchukuo

      Hi guys I have a form that has like 30 controls on them all of them have data that it loads to from a DB, is there a efficient way to only get the data or control that was modified? Thanks

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      You might like to take a look at Masks and flags using bit fields in .NET[^]. Assign each control on your form a binary value and set a flag if it's data gets modified. If there were less controls I would suggest an enumeration with the Flags attribute but I'm not sure (without looking it up) if an enum can handle that many.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      L 1 Reply Last reply
      0
      • M manchukuo

        Hi guys I have a form that has like 30 controls on them all of them have data that it loads to from a DB, is there a efficient way to only get the data or control that was modified? Thanks

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

        The last time I needeed to do something like that, I built it into a data class that held all the values. The textboxs were bound to those values through properties on the data class. Each property did its validation and then set a dirty flag if the value actually changed. Once the data object serialized itself, the dirty flags were reset.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        M 1 Reply Last reply
        0
        • H Henry Minute

          You might like to take a look at Masks and flags using bit fields in .NET[^]. Assign each control on your form a binary value and set a flag if it's data gets modified. If there were less controls I would suggest an enumeration with the Flags attribute but I'm not sure (without looking it up) if an enum can handle that many.

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Henry Minute wrote:

          I'm not sure if an enum can handle that many.

          :confused: "An enumeration is a named constant whose underlying type is any integral type except Char". So if you have it derive from int (the default) or uint, you get 32 flags; from long/ulong 64. That is one for each available bit.

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          H 1 Reply Last reply
          0
          • D Dave Kreskowiak

            The last time I needeed to do something like that, I built it into a data class that held all the values. The textboxs were bound to those values through properties on the data class. Each property did its validation and then set a dirty flag if the value actually changed. Once the data object serialized itself, the dirty flags were reset.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            M Offline
            M Offline
            manchukuo
            wrote on last edited by
            #5

            This particular way has the advantage of knowing which control was really modified, what i mean is that if a user has a textfield init with the text "Hello" and user erases/modifies and then retry the same value it shouldn't be marked as modified, doing this way will ensure that it has diferent data, but it seems that the vest way is to copy the init data in a structure/class for each form right?

            A 1 Reply Last reply
            0
            • M manchukuo

              This particular way has the advantage of knowing which control was really modified, what i mean is that if a user has a textfield init with the text "Hello" and user erases/modifies and then retry the same value it shouldn't be marked as modified, doing this way will ensure that it has diferent data, but it seems that the vest way is to copy the init data in a structure/class for each form right?

              A Offline
              A Offline
              AspDotNetDev
              wrote on last edited by
              #6

              manchukuo wrote:

              the vest way is to copy the init data in a structure/class for each form right?

              That's pretty much the standard. You could also compare it against the last value that was stored in the database, but that pretty much defeats the purpose of avoiding a database call. You can also get a hash of the initial data (e.g., GetHashCode) and compare that to the hash code for the new data (this will minimize the amount of memory used and will be correct most of the time). If you combine that with dirty checking, you will have a pretty good way of minimizing data transfer.

              [Forum Guidelines]

              M 1 Reply Last reply
              0
              • A AspDotNetDev

                manchukuo wrote:

                the vest way is to copy the init data in a structure/class for each form right?

                That's pretty much the standard. You could also compare it against the last value that was stored in the database, but that pretty much defeats the purpose of avoiding a database call. You can also get a hash of the initial data (e.g., GetHashCode) and compare that to the hash code for the new data (this will minimize the amount of memory used and will be correct most of the time). If you combine that with dirty checking, you will have a pretty good way of minimizing data transfer.

                [Forum Guidelines]

                M Offline
                M Offline
                manchukuo
                wrote on last edited by
                #7

                mmhh i see thanks for all your time and help i will try the hash stuff

                1 Reply Last reply
                0
                • L Luc Pattyn

                  Henry Minute wrote:

                  I'm not sure if an enum can handle that many.

                  :confused: "An enumeration is a named constant whose underlying type is any integral type except Char". So if you have it derive from int (the default) or uint, you get 32 flags; from long/ulong 64. That is one for each available bit.

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  H Offline
                  H Offline
                  Henry Minute
                  wrote on last edited by
                  #8

                  I notice that in your quote from my post you carefully avoided including the part in braces. Probably due to my age, as others have pointed out elsewhere, I couldn't remember if enums used a sensible storage strategy or not. Which is why I said 'without looking it up'.

                  Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                  L 1 Reply Last reply
                  0
                  • H Henry Minute

                    I notice that in your quote from my post you carefully avoided including the part in braces. Probably due to my age, as others have pointed out elsewhere, I couldn't remember if enums used a sensible storage strategy or not. Which is why I said 'without looking it up'.

                    Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    Only trying to help. I am convinced you would know when you looked it up, however I wanted to save you the trouble as you were concentrating on your game and/or celebrating your winnings. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                    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