all groups > dotnet windows forms databinding > september 2006 >
You're in the

dotnet windows forms databinding

group:

Problem when updating table with auto-id


Re: Problem when updating table with auto-id Bart Mermuys
9/26/2006 7:34:42 PM
dotnet windows forms databinding:
Hi,

[quoted text, click to view]

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


[quoted text, click to view]

Problem when updating table with auto-id Duong Nguyen
9/26/2006 8:42:40 PM
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.



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

Re: Problem when updating table with auto-id Duong Nguyen
9/27/2006 12:00:00 AM
Such a greate idea, thanks a lot!



--
Contact:
Bauman Moscow State Technical University
Russia, Moscow 105005
Tel: +7915-426-6272
ICQ: 160-223-078
YM: Chipheo2k
[quoted text, click to view]

AddThis Social Bookmark Button