Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / September 2006

Tip: Looking for answers? Try searching our database.

Problem when updating table with auto-id

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Duong Nguyen - 26 Sep 2006 17:45 GMT
Hello,
I have table with auto-id. Binding to a datagridview. One interesting
moment:
- the first time I run the application, I type some rows(in datagridview),
and press onto Update (call method update of the tableAdapter). I got the
error message: record with the Id = 1 already existed. I have tested with
some other tables and every time I got the same error. But if  I add only
one row at the first time, then from the second time when I open this form
to add many new rows and after that I press onto button Update it works ok
(without any error message). Pls explain.
thanks.

Signature

Contact:
Bauman Moscow State Technical University
Russia, Moscow 105005
Tel: +7915-426-6272
ICQ: 160-223-078
YM: Chipheo2k

Bart Mermuys - 26 Sep 2006 20:34 GMT
Hi,

> Hello,
> I have table with auto-id. Binding to a datagridview. One interesting
[quoted text clipped - 6 lines]
> to add many new rows and after that I press onto button Update it works ok
> (without any error message). Pls explain.

To support this auto-id in a batch mode, the DataColumn is set to
AutoIncrement, then when the update is performed the DB generated keys are
retrieved but *one* at a time.

So, let's say you're adding three new records:

id  ...
--  ---
0   ...
1   ...
2   ...

The id's are generated by the DataColumn, now when you perform the update,
the first row is inserted in the DB and it returns 1 as the key, but the
second row currently also has 1 as the key, so it fails ...

To avoid problems, set the DataColumn's AutoIncrementStep to -1, so the id's
generated by the DataColumn are negative, while the ones generated by the DB
are positive, this to avoid dupplicate keys *while* performing the update.

To set the DataColumn's AutoIncrementStep, double click on your DataSet in
solution explorer, select the id column inside the DataSet Schema Designer
and then open properties window.

HTH,
Greetings

> thanks.
Duong Nguyen - 27 Sep 2006 10:53 GMT
Such a greate idea, thanks a lot!

Signature

Contact:
Bauman Moscow State Technical University
Russia, Moscow 105005
Tel: +7915-426-6272
ICQ: 160-223-078
YM: Chipheo2k

> Hi,
>
[quoted text clipped - 39 lines]
>
>> thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.