Updating Datasets

Posted on 2006-05-25
Last Modified: 2010-04-23
I have a program that will be running on multiple computers are the same time. The program uses a dataset which stores the diffrent sticker number. More stickers can be added, where the StickerNo is the primary key because it needs to be unuiqe. I am running into a problem though. For example both program one and program two went through the startup process and all the information is stored into the datasets. Program one stores more records into the database. Then program two stored more records, one being with the same StickerNo. Because the datasets have never been updated since the new records are added, two records with the same PK (StickerNo) are added, and no exception is thrown. I need to figure out how to avoid this. ANY suggestions would help!
Question by:Gunit2507
    LVL 6

    Expert Comment

    HI Gunit2507,
            I am not getting why the error is not thrown, can please check the datatable design again i. e the primary key and all,

    and for the problem what u can do set the 'StickerNo' as identity colun i.e it will generate automatically and while entring the data the column will take the next value of the " max value + 'Identity Seed' " value, set it to one so that it increments by one,
    and while adding the data to DB dont generate the 'StickerNo' in backend only send all the column values except 'StickerNo' and the new row will be added with unique 'StickerNo' .

    LVL 6

    Accepted Solution

    Define the primay column on the dataset as given below :
    (And then update the dataset  it will automatically take care of duplicacy)
    (Use adapter to update the dataset with command objects)

                Dim pcol(0) As DataColumn
                pcol(0) = dataset.Tables("TableName").Columns("ColumnName")
                dataset.Tables("ColumnName").PrimaryKey = pcol

    Author Comment


    StickerNo is the primary key in the database and dataset, it is also set to be unique and does not accept DBNull values. It is also indexed with no duplicates. The StickerNo field will not necessarly be straight 1, 2, 3, 4, 5... It might be skipping numbers and such, and the records can't just be empty. Thats why I want to be able to enter the StickerNo.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now