Updating Datasets

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!
Gunit2507Asked:
Who is Participating?
 
manchConnect With a Mentor Commented:
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
0
 
SandeepRRCommented:
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' .

SandeepRR
0
 
Gunit2507Author Commented:
Hello,

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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.