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. BindingNavigator's AddNew vs. AutoIncrement DB fields

BindingNavigator's AddNew vs. AutoIncrement DB fields

Scheduled Pinned Locked Moved C#
questiondatabasecsharpvisual-studiohelp
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.
  • M Offline
    M Offline
    mrlucmorin
    wrote on last edited by
    #1

    Hi, First, I apologize if this is not the proper forum to ask my question. I have a .NET 2.0 Windows Form App which uses BindingNavigator, BindingSource and DataSet. The user can use the AddNew and Delete buttons of the BindingNavigator to Add/Delete records to the underlying typed DataSet. In my particular case, I'm showing a Work Order record whose PK is also the table's IDENTITY field (MS SQL 2005). My DataSet is setup with negative increment for this PK in order to avoid clashes. So, when the user clicks the AddNew button, he sees a negative Work Order number showing up until the Update method is called on the TableAdapter. This could be a source of confusion in some users, so I'd like to proceed differently. Should I handle this field manually, getting from the DB the highest Work Order number right when the record is created in the DataSet ? If so, how do I take care of concurrency in the case another user also creates a new Work Order before first user actualy commits his new record ? Or should I simply call Update right away when the record is created ? I assume this is a very common issue in DB programming. Thank for any tips. Luc Morin

    G 1 Reply Last reply
    0
    • M mrlucmorin

      Hi, First, I apologize if this is not the proper forum to ask my question. I have a .NET 2.0 Windows Form App which uses BindingNavigator, BindingSource and DataSet. The user can use the AddNew and Delete buttons of the BindingNavigator to Add/Delete records to the underlying typed DataSet. In my particular case, I'm showing a Work Order record whose PK is also the table's IDENTITY field (MS SQL 2005). My DataSet is setup with negative increment for this PK in order to avoid clashes. So, when the user clicks the AddNew button, he sees a negative Work Order number showing up until the Update method is called on the TableAdapter. This could be a source of confusion in some users, so I'd like to proceed differently. Should I handle this field manually, getting from the DB the highest Work Order number right when the record is created in the DataSet ? If so, how do I take care of concurrency in the case another user also creates a new Work Order before first user actualy commits his new record ? Or should I simply call Update right away when the record is created ? I assume this is a very common issue in DB programming. Thank for any tips. Luc Morin

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      There is no way of knowing for sure what id a record will get until it's created. If you use any method to guess the id (e.g. from the previous records), you might get it right most of the time, but not all the time. If you handle the id manually, you still won't get it right all the time. Sometimes some other user will have created a record, so the insert will fail. Then you would have to handle the error condition, give the id a new number and try to save it again. This might be acceptable, but one big drawback is that the more users you have, the more frequently this will happen. --- b { font-weight: normal; }

      M 1 Reply Last reply
      0
      • G Guffa

        There is no way of knowing for sure what id a record will get until it's created. If you use any method to guess the id (e.g. from the previous records), you might get it right most of the time, but not all the time. If you handle the id manually, you still won't get it right all the time. Sometimes some other user will have created a record, so the insert will fail. Then you would have to handle the error condition, give the id a new number and try to save it again. This might be acceptable, but one big drawback is that the more users you have, the more frequently this will happen. --- b { font-weight: normal; }

        M Offline
        M Offline
        mrlucmorin
        wrote on last edited by
        #3

        Guffa wrote:

        There is no way of knowing for sure what id a record will get until it's created. If you use any method to guess the id (e.g. from the previous records), you might get it right most of the time, but not all the time.

        Yes, this is exactly my concern. How do most apps handle this situation ? I was thinking of making the Work Order TextBox invisible until the user actuallty saves the record. What do you think ? Regards, Luc Morin

        D 1 Reply Last reply
        0
        • M mrlucmorin

          Guffa wrote:

          There is no way of knowing for sure what id a record will get until it's created. If you use any method to guess the id (e.g. from the previous records), you might get it right most of the time, but not all the time.

          Yes, this is exactly my concern. How do most apps handle this situation ? I was thinking of making the Work Order TextBox invisible until the user actuallty saves the record. What do you think ? Regards, Luc Morin

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

          You could make a call to a stored procedure that just creates a blank record in the table. The autoincremented value (ID) gets created, then the SP returns just that ID. You're code can then show a blank edit form so all the details can be filled in. Then the record can be written back to the table with the "checked-out" ID number. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          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