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. A simple ADO.NET and table design question

A simple ADO.NET and table design question

Scheduled Pinned Locked Moved Database
databasequestioncsharpdesignperformance
3 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.
  • D Offline
    D Offline
    DionChen
    wrote on last edited by
    #1

    Hi, All: I am writing my FIRST Windows Form Application in .NET to edit my MS Access database. In this Access DB, I have a table with two columns: EquipmentID and EquipmentDescription. Some other tables use the ID to refer the equipment. This application supports multiple users at the same time. That mean that it could be more than one user add new equipmment. I use in-memory DataSet to get user's input and then call Insert/Delete/Update methods. I am debating that whether I should use Access AutoNumber for the ID field, or I should just use DataReader to get the Max ID used, then Add 1 to create my new ID. The AutoNumber makes things simpler, but if I try to merge to DB later, I will have a lot of headaches. If I assign my own ID, I might have conflict with other users and fail the INSERT. So what is the typical way to achieve this, I know a lot of people have done this, please give me some ideas. Thanks in advance. Dion

    P A 2 Replies Last reply
    0
    • D DionChen

      Hi, All: I am writing my FIRST Windows Form Application in .NET to edit my MS Access database. In this Access DB, I have a table with two columns: EquipmentID and EquipmentDescription. Some other tables use the ID to refer the equipment. This application supports multiple users at the same time. That mean that it could be more than one user add new equipmment. I use in-memory DataSet to get user's input and then call Insert/Delete/Update methods. I am debating that whether I should use Access AutoNumber for the ID field, or I should just use DataReader to get the Max ID used, then Add 1 to create my new ID. The AutoNumber makes things simpler, but if I try to merge to DB later, I will have a lot of headaches. If I assign my own ID, I might have conflict with other users and fail the INSERT. So what is the typical way to achieve this, I know a lot of people have done this, please give me some ideas. Thanks in advance. Dion

      P Offline
      P Offline
      Peet Schultz
      wrote on last edited by
      #2

      If you use a GUID (Globally Unique Identifier) as the ID, you should have something that can be ported to any platform as well as solve your Identity problems. I have previously used a VB6 function that produced GUID's, and am sure you should find one for .Net. Regards Peet Schultz Centurion SA YASP

      1 Reply Last reply
      0
      • D DionChen

        Hi, All: I am writing my FIRST Windows Form Application in .NET to edit my MS Access database. In this Access DB, I have a table with two columns: EquipmentID and EquipmentDescription. Some other tables use the ID to refer the equipment. This application supports multiple users at the same time. That mean that it could be more than one user add new equipmment. I use in-memory DataSet to get user's input and then call Insert/Delete/Update methods. I am debating that whether I should use Access AutoNumber for the ID field, or I should just use DataReader to get the Max ID used, then Add 1 to create my new ID. The AutoNumber makes things simpler, but if I try to merge to DB later, I will have a lot of headaches. If I assign my own ID, I might have conflict with other users and fail the INSERT. So what is the typical way to achieve this, I know a lot of people have done this, please give me some ideas. Thanks in advance. Dion

        A Offline
        A Offline
        Alexander Kojevnikov
        wrote on last edited by
        #3

        There're was an article on MSDN covering this issue, but I cannot find it. What it suggests is to configure your EquipmentID to use negative autoincrement values: ds.Tables["Equipment"].Columns["EquipmentID"].AutoIncrementSeed = -1; ds.Tables["Equipment"].Columns["EquipmentID"].AutoIncrementStep = -1; ...and to modify your insert SP (or insert code if you use Access) to return the newly created identity value. SP would look like this: CREATE PROCEDURE dbo.daInsertEquipment ( @EquipmentID int OUT, @EquipmentDescription nvarchar(200) ) AS INSERT INTO Equipment (EquipmentID, EquipmentDescription) VALUES (@EquipmentID, @EquipmentDescription) SET @id = SCOPE_IDENTITY() HTH Alexandre Kojevnikov MCP (SQL2K) Leuven, Belgium

        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