dotnet windows forms databinding:
Hi,
[quoted text, click to view] "Duong Nguyen" <Duongnguyen@mail.ru> wrote in message
news:%23Nt9GqY4GHA.3964@TK2MSFTNGP04.phx.gbl...
> 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.
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] > thanks.
>
>
>
> --
> Contact:
> Bauman Moscow State Technical University
> Russia, Moscow 105005
> Tel: +7915-426-6272
> ICQ: 160-223-078
> YM: Chipheo2k
>