473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 1111
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard Payne | last post by:
I am developing a web application that utilises multiple grids, panels, validation controls etc on the same page. I have added the appropriate code to pop up dialogs to confirm delete in...
0
by: sJeev via DotNetMonster.com | last post by:
Please help, I am very new to asp.net and data grids have got me stuck for a loooong time. I can either have the right content in my datagrids or make them editable. In the first case, I make...
4
by: ree32 | last post by:
I have a placeholder and depending on a user input(a drop downlist) when the user clicks a button I dynamically create a number of datagrids and fill them with data from a database. But the problem...
2
by: OHM | last post by:
Windows Forms Controls. Has anyone personally read and recommends a good book which includes good coverage on DataGrids as this seems to be one of the most common problem areas. Regards - OHM
1
by: Joăo Santa Bárbara | last post by:
Hi all. i have a strange problem i have done a User Control, in wich i have placed a few buttons inside it and place it in an form. in the previous version of .NET (2003), i have try to access...
6
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost...
4
by: tshad | last post by:
I am trying to hide and show certain parts of my code (which I have no problem doing with DW). In VS 2003, it won't let you use <div runat="server"to section of parts of my code in a table. This...
6
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, is there a shorter way to write the following: System.Data.DataColumn keys = new System.Data.DataColumn; // Add the column to the array. keys = dataTable.Columns; // Set the...
0
by: Sebastijan | last post by:
Hi I am interested in DbConnection.GetSchema method of ODP.NET oracle library. When I call (to get primary keys metadata) DataTable pkeys = DbConnection.GetSchema("PrimaryKeys"... foreach...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.