471,071 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

Please help with Datagrids and Access primarykeys problem!

Hello!

I have 4 tables where the first is parent of the second and second parent of
the the third and so on...

These I need to have as Datagrids loaded from access (one grid for each
table, not all tables in the same grid). Then I edit the values and then
save back to the Access Database, keeping the relations.

My problem is this:
If I load the dataset, all the tables will remember the primary keys from
what's set in Access and continue to increment from those values.. that
means if I in Table1 create a post (via the datagrid) it can get the value
10 in the PirmaryKey column.. and then if I remove it.. and create another
one it will become number 11.. which is all fine.. BUT then when I save this
to the database the database has no information of that there was a "created
and deleted value" and will create that post that has number 11 in the
dataset and give it number 10 in access... this means that all the
childrecord in Table2 will get the wrong parent ID...

How on earth do I do this???

Best regards
/Lars Netzel

Nov 21 '05 #1
5 1027
Lars,

Do you use autokeys?.

Cor
Nov 21 '05 #2
I use AutoIncrement in the Dataset it gets it from access automatically it
seems when I fill from the OledbAdapter!

If that is the same thing as autokeys I'm not sure...
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Or****************@TK2MSFTNGP11.phx.gbl...
Lars,

Do you use autokeys?.

Cor

Nov 21 '05 #3
Lars,

Can you change that with a method of guid's or is it an existing database?

Cor
Nov 21 '05 #4


"Lars Netzel" <no****@doamin.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Hello!

I have 4 tables where the first is parent of the second and second parent
of the the third and so on...

These I need to have as Datagrids loaded from access (one grid for each
table, not all tables in the same grid). Then I edit the values and then
save back to the Access Database, keeping the relations.

My problem is this:
If I load the dataset, all the tables will remember the primary keys from
what's set in Access and continue to increment from those values.. that
means if I in Table1 create a post (via the datagrid) it can get the value
10 in the PirmaryKey column.. and then if I remove it.. and create another
one it will become number 11.. which is all fine.. BUT then when I save
this to the database the database has no information of that there was a
"created and deleted value" and will create that post that has number 11
in the dataset and give it number 10 in access... this means that all the
childrecord in Table2 will get the wrong parent ID...

How on earth do I do this???

Best regards
/Lars Netzel


One simple way would be to just put the grids in separate screens.
Oh, obviously, make sure you just show one screen at a time.
Make the user add the main entry in one screen first, then the children
then the relationships.

The GUID thing would be neater but you've got to change the database
structure and maybe that's not a simple option if you have other code
already.
Nov 21 '05 #5
The trick to this is to have your AutoIncrementSeed set to negative 1 (-1).

All your disconected additions will have negative values (no collissions)
with the records in Access. When you Update to the database, the Autonumber
feature of Access will create positive values. There is an even a way for
the child recrods to be updated locally with the new Access positive
autonumbers.

I've never tried it myself, but I've read about it many times. (GUIDs are
definately simpler, at least conceptually).

http://msdn.microsoft.com/msdnmag/is...s/default.aspx

Greg

"Lars Netzel" <no****@doamin.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Hello!

I have 4 tables where the first is parent of the second and second parent
of the the third and so on...

These I need to have as Datagrids loaded from access (one grid for each
table, not all tables in the same grid). Then I edit the values and then
save back to the Access Database, keeping the relations.

My problem is this:
If I load the dataset, all the tables will remember the primary keys from
what's set in Access and continue to increment from those values.. that
means if I in Table1 create a post (via the datagrid) it can get the value
10 in the PirmaryKey column.. and then if I remove it.. and create another
one it will become number 11.. which is all fine.. BUT then when I save
this to the database the database has no information of that there was a
"created and deleted value" and will create that post that has number 11
in the dataset and give it number 10 in access... this means that all the
childrecord in Table2 will get the wrong parent ID...

How on earth do I do this???

Best regards
/Lars Netzel

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by sJeev via DotNetMonster.com | last post: by
1 post views Thread by Joăo Santa Bárbara | last post: by
6 posts views Thread by Steve Hershoff | last post: by
4 posts views Thread by tshad | last post: by
6 posts views Thread by =?Utf-8?B?cm9kY2hhcg==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.