A little background:
I use three Datagrids that are in a child parent relation.
I Use Negative Autoincrement on the the DataTables and that's workning nice.
My problem is when I Update these grid and write to the database and I set
the new Primary Keys and related Fields to the new asigned atuonumbers in
the Access.
The following Sub is the RowUpdated for the TopGrid's Adapter that will get
the new ID and then set that as a ParentID in Datatable for the the Next
Grid.
'---------------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------------------------------------------
Private Sub adpProjParts_RowUpdated(ByVal sender As Object, ByVal e As
System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles adpProjParts.RowUpdated
If e.StatementType = StatementType.Insert Then
Dim cmd As New OleDb.OleDbCommand("SELECT @@IDENTITY", e.Command.Connection)
Dim OldId As Long = e.Row()("PRP_ID") 'This is primary key
Dim NewID As Long = cmd.ExecuteScalar 'This is the New PrimaryKey ID
CopyDataViews()
e.Row()("PRP_ID") = NewID
e.Row().AcceptChanges()
Me.dvProjCodes_COPY.RowFilter = Nothing
Me.dvProjCodes_COPY.RowFilter = "prco_prpid=" & OldId
Dim I As Long
Dim alRows As New ArrayList
Dim drvRowIter As DataRowView
For I = Me.dvProjCodes_COPY.Count - 1 To 0 Step -1
alRows.Add(Me.dvProjCodes_COPY.Item(I))
Next
Me.dvProjCodes_COPY.RowFilter = Nothing
m_bIsSaving = True
For Each drvRowIter In alRows
drvRowIter.Row("prco_prpid") = NewID
Next
m_bIsSaving = False
End If
End Sub
'---------------------------------------------------------------------------
--------------------------
If I debug this Sub, everythign is fine and I everything seems to get the
right IDs when stepping thru it. BUT when I later check the database, One or
more of the Items in the next grid (that I just changed the Parent ID on
with this Sub) has gotten the old Negative Autonumber back.. and Of course
the relation in Access is lost.
I have been trying to figure out what rows are "changed" back to the
Negative ID and the only thing I have seen that's even remotly close, is
that it's often is the Row in the datagrid that I have my cursor on when I
trigger the Save (Update on the dataset). But that' snot completely true, it
also seems like the rows I have HAD selected and then Left also the Get
Negative ID back..
BUT.. here's the weird part.. it shouldn't matter what Rows I have selected
in the grids.. since the RowUpdated happens AFTER all that.. so I'm
completely Confused right now.
To me it seems like even though the RowUpdated Sub is working alright when
stepping thru it, some of the Items in the DataTable that I set the New
ParentID on, changes back after that...
I know it's hard to explain this problem...
PLEASE HELP!!!
/Lars Netzel 14 2063
You dont need any of this code.
Lets say you add some records right ?,, they will have negative PK's on the
Grid, once you run an update to the datasource, these will be assigned new
positive ID's providing your Acccess Corresponding PK is Autoincremented in
the design.
You can prove this.
1.) Create a table with two fields in it. One being the ID ( Primary key )
and set this to Autoincrement in Access.
2.) Put a grid on a form and bind the grid to the dataset.datatable.
3.) Put the following code in the Load event of the form
Me.DataSet11.Tables(0).Columns(0).AutoIncrementSee d = -1
Me.DataSet11.Tables(0).Columns(0).AutoIncrementSte p = -1
Me.OleDbDataAdapter1.Fill(Me.DataSet11)
4.) Create two buttons one for Fill and One for Update put the code in for
that.
5.) Create four entries, ( see the negative keys ).
6.) Click the Update and then Load.
7.) Bingo Your four new records all have numbers 1-4 for their PK.
8.) Updating the data in those non PK keys does not affect the PK, try it.
HTH - OHM ( Terry Burns )
"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl... A little background:
I use three Datagrids that are in a child parent relation.
I Use Negative Autoincrement on the the DataTables and that's workning
nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
The following Sub is the RowUpdated for the TopGrid's Adapter that will
get the new ID and then set that as a ParentID in Datatable for the the Next Grid.
'--------------------------------------------------------------------------- --------------------------------------------------------------------------
-- ------------------------------------------------------------------------
Private Sub adpProjParts_RowUpdated(ByVal sender As Object, ByVal e As System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles
adpProjParts.RowUpdated If e.StatementType = StatementType.Insert Then
Dim cmd As New OleDb.OleDbCommand("SELECT @@IDENTITY",
e.Command.Connection) Dim OldId As Long = e.Row()("PRP_ID") 'This is primary key
Dim NewID As Long = cmd.ExecuteScalar 'This is the New PrimaryKey ID
CopyDataViews()
e.Row()("PRP_ID") = NewID
e.Row().AcceptChanges()
Me.dvProjCodes_COPY.RowFilter = Nothing
Me.dvProjCodes_COPY.RowFilter = "prco_prpid=" & OldId
Dim I As Long
Dim alRows As New ArrayList
Dim drvRowIter As DataRowView
For I = Me.dvProjCodes_COPY.Count - 1 To 0 Step -1
alRows.Add(Me.dvProjCodes_COPY.Item(I))
Next
Me.dvProjCodes_COPY.RowFilter = Nothing
m_bIsSaving = True
For Each drvRowIter In alRows
drvRowIter.Row("prco_prpid") = NewID
Next
m_bIsSaving = False
End If
End Sub
'--------------------------------------------------------------------------- --------------------------
If I debug this Sub, everythign is fine and I everything seems to get the right IDs when stepping thru it. BUT when I later check the database, One
or more of the Items in the next grid (that I just changed the Parent ID on with this Sub) has gotten the old Negative Autonumber back.. and Of course the relation in Access is lost.
I have been trying to figure out what rows are "changed" back to the Negative ID and the only thing I have seen that's even remotly close, is that it's often is the Row in the datagrid that I have my cursor on when I trigger the Save (Update on the dataset). But that' snot completely true,
it also seems like the rows I have HAD selected and then Left also the Get Negative ID back..
BUT.. here's the weird part.. it shouldn't matter what Rows I have
selected in the grids.. since the RowUpdated happens AFTER all that.. so I'm completely Confused right now.
To me it seems like even though the RowUpdated Sub is working alright when stepping thru it, some of the Items in the DataTable that I set the New ParentID on, changes back after that...
I know it's hard to explain this problem...
PLEASE HELP!!!
/Lars Netzel
The PK is not the problem... it's the ParentID (foreign key) column in the
Next table that's the problem.. which does not get the "new" ID from
access...
So that's why I use the code to Catch the New ID given by Access in the
RowUpdated Event.. and then use ID to set as the Foregin Key in the next
table.. BUT here's where the troubles comes..
Some of the Rows that I "manually" set the foregin key on are fine, but the
row that is selected in the grid... for some reason get'äs the Negative
Foreign key value back before it's saved..
/Lars
"One Handed Man ( OHM#)" <news.microsoft.com> skrev i meddelandet
news:%2****************@TK2MSFTNGP11.phx.gbl... You dont need any of this code.
Lets say you add some records right ?,, they will have negative PK's on
the Grid, once you run an update to the datasource, these will be assigned new positive ID's providing your Acccess Corresponding PK is Autoincremented
in the design.
You can prove this.
1.) Create a table with two fields in it. One being the ID ( Primary key ) and set this to Autoincrement in Access.
2.) Put a grid on a form and bind the grid to the dataset.datatable.
3.) Put the following code in the Load event of the form Me.DataSet11.Tables(0).Columns(0).AutoIncrementSee d = -1 Me.DataSet11.Tables(0).Columns(0).AutoIncrementSte p = -1 Me.OleDbDataAdapter1.Fill(Me.DataSet11)
4.) Create two buttons one for Fill and One for Update put the code in for that. 5.) Create four entries, ( see the negative keys ). 6.) Click the Update and then Load. 7.) Bingo Your four new records all have numbers 1-4 for their PK. 8.) Updating the data in those non PK keys does not affect the PK, try it.
HTH - OHM ( Terry Burns ) "Lars Netzel" <[stop_spam]@host.topdomain> wrote in message news:uH**************@TK2MSFTNGP09.phx.gbl... A little background:
I use three Datagrids that are in a child parent relation.
I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I
set the new Primary Keys and related Fields to the new asigned atuonumbers
in the Access.
The following Sub is the RowUpdated for the TopGrid's Adapter that will
get the new ID and then set that as a ParentID in Datatable for the the Next Grid.
'--------------------------------------------------------------------------- -------------------------------------------------------------------------- -- ------------------------------------------------------------------------
Private Sub adpProjParts_RowUpdated(ByVal sender As Object, ByVal e As System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles adpProjParts.RowUpdated If e.StatementType = StatementType.Insert Then
Dim cmd As New OleDb.OleDbCommand("SELECT @@IDENTITY",
e.Command.Connection) Dim OldId As Long = e.Row()("PRP_ID") 'This is primary key
Dim NewID As Long = cmd.ExecuteScalar 'This is the New PrimaryKey ID
CopyDataViews()
e.Row()("PRP_ID") = NewID
e.Row().AcceptChanges()
Me.dvProjCodes_COPY.RowFilter = Nothing
Me.dvProjCodes_COPY.RowFilter = "prco_prpid=" & OldId
Dim I As Long
Dim alRows As New ArrayList
Dim drvRowIter As DataRowView
For I = Me.dvProjCodes_COPY.Count - 1 To 0 Step -1
alRows.Add(Me.dvProjCodes_COPY.Item(I))
Next
Me.dvProjCodes_COPY.RowFilter = Nothing
m_bIsSaving = True
For Each drvRowIter In alRows
drvRowIter.Row("prco_prpid") = NewID
Next
m_bIsSaving = False
End If
End Sub
'--------------------------------------------------------------------------- --------------------------
If I debug this Sub, everythign is fine and I everything seems to get
the right IDs when stepping thru it. BUT when I later check the database,
One or more of the Items in the next grid (that I just changed the Parent ID on with this Sub) has gotten the old Negative Autonumber back.. and Of
course the relation in Access is lost.
I have been trying to figure out what rows are "changed" back to the Negative ID and the only thing I have seen that's even remotly close, is that it's often is the Row in the datagrid that I have my cursor on when
I trigger the Save (Update on the dataset). But that' snot completely
true, it also seems like the rows I have HAD selected and then Left also the Get Negative ID back..
BUT.. here's the weird part.. it shouldn't matter what Rows I have selected in the grids.. since the RowUpdated happens AFTER all that.. so I'm completely Confused right now.
To me it seems like even though the RowUpdated Sub is working alright
when stepping thru it, some of the Items in the DataTable that I set the New ParentID on, changes back after that...
I know it's hard to explain this problem...
PLEASE HELP!!!
/Lars Netzel
How have you got these relationships defined?
You can create a relation in the dataset and bind the Details grid to this,
that way it should work.
Regards OHM (Terry Burns)
"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:eX**************@TK2MSFTNGP12.phx.gbl... The PK is not the problem... it's the ParentID (foreign key) column in the Next table that's the problem.. which does not get the "new" ID from access...
So that's why I use the code to Catch the New ID given by Access in the RowUpdated Event.. and then use ID to set as the Foregin Key in the next table.. BUT here's where the troubles comes..
Some of the Rows that I "manually" set the foregin key on are fine, but
the row that is selected in the grid... for some reason get'äs the Negative Foreign key value back before it's saved..
/Lars
"One Handed Man ( OHM#)" <news.microsoft.com> skrev i meddelandet news:%2****************@TK2MSFTNGP11.phx.gbl... You dont need any of this code.
Lets say you add some records right ?,, they will have negative PK's on the Grid, once you run an update to the datasource, these will be assigned
new positive ID's providing your Acccess Corresponding PK is Autoincremented in the design.
You can prove this.
1.) Create a table with two fields in it. One being the ID ( Primary
key ) and set this to Autoincrement in Access.
2.) Put a grid on a form and bind the grid to the dataset.datatable.
3.) Put the following code in the Load event of the form Me.DataSet11.Tables(0).Columns(0).AutoIncrementSee d = -1 Me.DataSet11.Tables(0).Columns(0).AutoIncrementSte p = -1 Me.OleDbDataAdapter1.Fill(Me.DataSet11)
4.) Create two buttons one for Fill and One for Update put the code in
for that. 5.) Create four entries, ( see the negative keys ). 6.) Click the Update and then Load. 7.) Bingo Your four new records all have numbers 1-4 for their PK. 8.) Updating the data in those non PK keys does not affect the PK, try
it.
HTH - OHM ( Terry Burns ) "Lars Netzel" <[stop_spam]@host.topdomain> wrote in message news:uH**************@TK2MSFTNGP09.phx.gbl... A little background:
I use three Datagrids that are in a child parent relation.
I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
The following Sub is the RowUpdated for the TopGrid's Adapter that
will get the new ID and then set that as a ParentID in Datatable for the the
Next Grid.
'---------------------------------------------------------------------------
-------------------------------------------------------------------------- -- ------------------------------------------------------------------------ Private Sub adpProjParts_RowUpdated(ByVal sender As Object, ByVal e As System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles
adpProjParts.RowUpdated If e.StatementType = StatementType.Insert Then
Dim cmd As New OleDb.OleDbCommand("SELECT @@IDENTITY",
e.Command.Connection) Dim OldId As Long = e.Row()("PRP_ID") 'This is primary key
Dim NewID As Long = cmd.ExecuteScalar 'This is the New PrimaryKey ID
CopyDataViews()
e.Row()("PRP_ID") = NewID
e.Row().AcceptChanges()
Me.dvProjCodes_COPY.RowFilter = Nothing
Me.dvProjCodes_COPY.RowFilter = "prco_prpid=" & OldId
Dim I As Long
Dim alRows As New ArrayList
Dim drvRowIter As DataRowView
For I = Me.dvProjCodes_COPY.Count - 1 To 0 Step -1
alRows.Add(Me.dvProjCodes_COPY.Item(I))
Next
Me.dvProjCodes_COPY.RowFilter = Nothing
m_bIsSaving = True
For Each drvRowIter In alRows
drvRowIter.Row("prco_prpid") = NewID
Next
m_bIsSaving = False
End If
End Sub
'--------------------------------------------------------------------------- --------------------------
If I debug this Sub, everythign is fine and I everything seems to get the right IDs when stepping thru it. BUT when I later check the database, One or more of the Items in the next grid (that I just changed the Parent ID
on with this Sub) has gotten the old Negative Autonumber back.. and Of course the relation in Access is lost.
I have been trying to figure out what rows are "changed" back to the Negative ID and the only thing I have seen that's even remotly close,
is that it's often is the Row in the datagrid that I have my cursor on
when I trigger the Save (Update on the dataset). But that' snot completely true, it also seems like the rows I have HAD selected and then Left also the
Get Negative ID back..
BUT.. here's the weird part.. it shouldn't matter what Rows I have
selected in the grids.. since the RowUpdated happens AFTER all that.. so I'm completely Confused right now.
To me it seems like even though the RowUpdated Sub is working alright when stepping thru it, some of the Items in the DataTable that I set the
New ParentID on, changes back after that...
I know it's hard to explain this problem...
PLEASE HELP!!!
/Lars Netzel
Tried that, gave the same result so the relations actually worked but some
rows still got the Wrong Foregn Key when written to the databasen... which
means the Negativ Foregin key that the Dataset Generated for the Parent
Table.
So I'm thinking it must be cause of something else.. or?
What about that it happens to the row that is selected in the Grid... any
ideas why it happens to that one?
I have checked to see if there are any other events triggred (like Position
Changed) and it was but those are handled with a Global Variable and they
don't do anything.. so I'm sure that the Save I do and all the Updates are
not interfreered by any other code I have written somewhere else... I
hope...
IT's really really frustrating, don't know where to turn anymore really...
and I really really need it done by today..
I Appiciate any help I can get here!
/Lars
"One Handed Man ( OHM#)" <news.microsoft.com> skrev i meddelandet
news:%2****************@tk2msftngp13.phx.gbl... How have you got these relationships defined?
You can create a relation in the dataset and bind the Details grid to
this, that way it should work.
Regards OHM (Terry Burns) "Lars Netzel" <[stop_spam]@host.topdomain> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... The PK is not the problem... it's the ParentID (foreign key) column in
the Next table that's the problem.. which does not get the "new" ID from access...
So that's why I use the code to Catch the New ID given by Access in the RowUpdated Event.. and then use ID to set as the Foregin Key in the next table.. BUT here's where the troubles comes..
Some of the Rows that I "manually" set the foregin key on are fine, but the row that is selected in the grid... for some reason get'äs the Negative Foreign key value back before it's saved..
/Lars
"One Handed Man ( OHM#)" <news.microsoft.com> skrev i meddelandet news:%2****************@TK2MSFTNGP11.phx.gbl... You dont need any of this code.
Lets say you add some records right ?,, they will have negative PK's
on the Grid, once you run an update to the datasource, these will be assigned new positive ID's providing your Acccess Corresponding PK is
Autoincremented in the design.
You can prove this.
1.) Create a table with two fields in it. One being the ID ( Primary key ) and set this to Autoincrement in Access.
2.) Put a grid on a form and bind the grid to the dataset.datatable.
3.) Put the following code in the Load event of the form Me.DataSet11.Tables(0).Columns(0).AutoIncrementSee d = -1 Me.DataSet11.Tables(0).Columns(0).AutoIncrementSte p = -1 Me.OleDbDataAdapter1.Fill(Me.DataSet11)
4.) Create two buttons one for Fill and One for Update put the code in for that. 5.) Create four entries, ( see the negative keys ). 6.) Click the Update and then Load. 7.) Bingo Your four new records all have numbers 1-4 for their PK. 8.) Updating the data in those non PK keys does not affect the PK, try it.
HTH - OHM ( Terry Burns ) "Lars Netzel" <[stop_spam]@host.topdomain> wrote in message news:uH**************@TK2MSFTNGP09.phx.gbl... > A little background: > > I use three Datagrids that are in a child parent relation. > > I Use Negative Autoincrement on the the DataTables and that's
workning nice. > > My problem is when I Update these grid and write to the database and
I set > the new Primary Keys and related Fields to the new asigned
atuonumbers in > the Access. > > The following Sub is the RowUpdated for the TopGrid's Adapter that will get > the new ID and then set that as a ParentID in Datatable for the the Next > Grid. > >
'---------------------------------------------------------------------------
-------------------------------------------------------------------------- -- ------------------------------------------------------------------------ > > Private Sub adpProjParts_RowUpdated(ByVal sender As Object, ByVal e
As > System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles adpProjParts.RowUpdated > > If e.StatementType = StatementType.Insert Then > > Dim cmd As New OleDb.OleDbCommand("SELECT @@IDENTITY", e.Command.Connection) > > Dim OldId As Long = e.Row()("PRP_ID") 'This is primary key > > Dim NewID As Long = cmd.ExecuteScalar 'This is the New PrimaryKey ID > > CopyDataViews() > > e.Row()("PRP_ID") = NewID > > e.Row().AcceptChanges() > > Me.dvProjCodes_COPY.RowFilter = Nothing > > Me.dvProjCodes_COPY.RowFilter = "prco_prpid=" & OldId > > Dim I As Long > > Dim alRows As New ArrayList > > Dim drvRowIter As DataRowView > > For I = Me.dvProjCodes_COPY.Count - 1 To 0 Step -1 > > alRows.Add(Me.dvProjCodes_COPY.Item(I)) > > Next > > Me.dvProjCodes_COPY.RowFilter = Nothing > > m_bIsSaving = True > > For Each drvRowIter In alRows > > drvRowIter.Row("prco_prpid") = NewID > > Next > > m_bIsSaving = False > > End If > > End Sub > >
'--------------------------------------------------------------------------- > -------------------------- > > If I debug this Sub, everythign is fine and I everything seems to
get the > right IDs when stepping thru it. BUT when I later check the
database, One or > more of the Items in the next grid (that I just changed the Parent
ID on > with this Sub) has gotten the old Negative Autonumber back.. and Of course > the relation in Access is lost. > > I have been trying to figure out what rows are "changed" back to the > Negative ID and the only thing I have seen that's even remotly
close, is > that it's often is the Row in the datagrid that I have my cursor on when I > trigger the Save (Update on the dataset). But that' snot completely true, it > also seems like the rows I have HAD selected and then Left also the Get > Negative ID back.. > > BUT.. here's the weird part.. it shouldn't matter what Rows I have selected > in the grids.. since the RowUpdated happens AFTER all that.. so I'm > completely Confused right now. > > To me it seems like even though the RowUpdated Sub is working
alright when > stepping thru it, some of the Items in the DataTable that I set the
New > ParentID on, changes back after that... > > I know it's hard to explain this problem... > > PLEASE HELP!!! > > /Lars Netzel > > > > > > > > > >
Hi Lars,
Did you do that
ds.update....
ds.clear
ds.fill.........................
I know it looks not very advanced, however it is a good start to investigage
the problem in my opinion.
Cor
Yes.. I did
And the problems come already in the Update Methid!
Also I just saw that When I have saved one time and then it reloads.. I get
the right ID's set on the PK fields.. BUT since the Autoincrement is set
to -1 it starts on the last "real" Id and then count backwards.. and the
gives me a conflict off course..
/Lars
"Cor Ligthert" <no**********@planet.nl> skrev i meddelandet
news:uO*************@tk2msftngp13.phx.gbl... Hi Lars,
Did you do that ds.update.... ds.clear ds.fill......................... I know it looks not very advanced, however it is a good start to
investigage the problem in my opinion.
Cor
Hi Lars,
I did not use that -1 method yet, however when you do that, did you set
after the fill as well the seed again on -1?
Cor
No, you have to se the Seed and Step Before you fill your dataset...
otherwise it's gonna use starting values depending on the PK exsisting in
table...
Then you'll get the problem of Counting backwards from a positive number..
/Lars
"Cor Ligthert" <no**********@planet.nl> skrev i meddelandet
news:uj**************@TK2MSFTNGP10.phx.gbl... Hi Lars,
I did not use that -1 method yet, however when you do that, did you set after the fill as well the seed again on -1?
Cor
Lars,
When you define the ForeignKeyConstraint (part of the DataRelation) you need
to set the ForeignKeyConstraint.UpdateRule to Rule.Cascade.
This will cause the child rows FK field to be updated to the parent row PK
field when the DataSet.Update command returns the PK from the database.
As OHM has stated, the DataSet will largely take care of all the update on
both the Child & Parent for you. You need to be certain that you define the
DataSet correctly is the Rub!
If you are only defining the DataRelation, you can use
DataRelation.ChildKeyConstraint to retrieve the ForeignKeyConstraint object
that was created as part of the DataRelation.
If I didn't the other day, I would strongly recommend you review the
relevant chapters in Sceppa's book!
For a good tutorial on ADO.NET as well as a good desk reference once you
know ADO.NET see David Sceppa's book "Microsoft ADO.NET - Core Reference"
from MS press.
Hope this helps
Jay
"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:uE*************@TK2MSFTNGP09.phx.gbl... Tried that, gave the same result so the relations actually worked but some rows still got the Wrong Foregn Key when written to the databasen... which means the Negativ Foregin key that the Dataset Generated for the Parent Table.
So I'm thinking it must be cause of something else.. or?
What about that it happens to the row that is selected in the Grid... any ideas why it happens to that one?
I have checked to see if there are any other events triggred (like
Position Changed) and it was but those are handled with a Global Variable and they don't do anything.. so I'm sure that the Save I do and all the Updates are not interfreered by any other code I have written somewhere else... I hope...
IT's really really frustrating, don't know where to turn anymore really... and I really really need it done by today..
I Appiciate any help I can get here!
/Lars
"One Handed Man ( OHM#)" <news.microsoft.com> skrev i meddelandet news:%2****************@tk2msftngp13.phx.gbl... How have you got these relationships defined?
You can create a relation in the dataset and bind the Details grid to this, that way it should work.
Regards OHM (Terry Burns) "Lars Netzel" <[stop_spam]@host.topdomain> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... The PK is not the problem... it's the ParentID (foreign key) column in the Next table that's the problem.. which does not get the "new" ID from access...
So that's why I use the code to Catch the New ID given by Access in
the RowUpdated Event.. and then use ID to set as the Foregin Key in the
next table.. BUT here's where the troubles comes..
Some of the Rows that I "manually" set the foregin key on are fine,
but the row that is selected in the grid... for some reason get'äs the
Negative Foreign key value back before it's saved..
/Lars
"One Handed Man ( OHM#)" <news.microsoft.com> skrev i meddelandet news:%2****************@TK2MSFTNGP11.phx.gbl... > You dont need any of this code. > > Lets say you add some records right ?,, they will have negative PK's on the > Grid, once you run an update to the datasource, these will be
assigned new > positive ID's providing your Acccess Corresponding PK is Autoincremented in > the design. > > You can prove this. > > 1.) Create a table with two fields in it. One being the ID ( Primary key ) > and set this to Autoincrement in Access. > > 2.) Put a grid on a form and bind the grid to the dataset.datatable. > > 3.) Put the following code in the Load event of the form > Me.DataSet11.Tables(0).Columns(0).AutoIncrementSee d = -1 > Me.DataSet11.Tables(0).Columns(0).AutoIncrementSte p = -1 > Me.OleDbDataAdapter1.Fill(Me.DataSet11) > > 4.) Create two buttons one for Fill and One for Update put the code
in for > that. > 5.) Create four entries, ( see the negative keys ). > 6.) Click the Update and then Load. > 7.) Bingo Your four new records all have numbers 1-4 for their PK. > 8.) Updating the data in those non PK keys does not affect the PK,
try it. > > > HTH - OHM ( Terry Burns ) > > > > "Lars Netzel" <[stop_spam]@host.topdomain> wrote in message > news:uH**************@TK2MSFTNGP09.phx.gbl... > > A little background: > > > > I use three Datagrids that are in a child parent relation. > > > > I Use Negative Autoincrement on the the DataTables and that's workning > nice. > > > > My problem is when I Update these grid and write to the database
and I set > > the new Primary Keys and related Fields to the new asigned atuonumbers in > > the Access. > > > > The following Sub is the RowUpdated for the TopGrid's Adapter that will > get > > the new ID and then set that as a ParentID in Datatable for the
the Next > > Grid. > > > > >
'--------------------------------------------------------------------------- >
-------------------------------------------------------------------------- > -- > ------------------------------------------------------------------------ > > > > Private Sub adpProjParts_RowUpdated(ByVal sender As Object, ByVal
e As > > System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles > adpProjParts.RowUpdated > > > > If e.StatementType = StatementType.Insert Then > > > > Dim cmd As New OleDb.OleDbCommand("SELECT @@IDENTITY", > e.Command.Connection) > > > > Dim OldId As Long = e.Row()("PRP_ID") 'This is primary key > > > > Dim NewID As Long = cmd.ExecuteScalar 'This is the New PrimaryKey
ID > > > > CopyDataViews() > > > > e.Row()("PRP_ID") = NewID > > > > e.Row().AcceptChanges() > > > > Me.dvProjCodes_COPY.RowFilter = Nothing > > > > Me.dvProjCodes_COPY.RowFilter = "prco_prpid=" & OldId > > > > Dim I As Long > > > > Dim alRows As New ArrayList > > > > Dim drvRowIter As DataRowView > > > > For I = Me.dvProjCodes_COPY.Count - 1 To 0 Step -1 > > > > alRows.Add(Me.dvProjCodes_COPY.Item(I)) > > > > Next > > > > Me.dvProjCodes_COPY.RowFilter = Nothing > > > > m_bIsSaving = True > > > > For Each drvRowIter In alRows > > > > drvRowIter.Row("prco_prpid") = NewID > > > > Next > > > > m_bIsSaving = False > > > > End If > > > > End Sub > > > > >
'--------------------------------------------------------------------------- > > -------------------------- > > > > If I debug this Sub, everythign is fine and I everything seems to get the > > right IDs when stepping thru it. BUT when I later check the database, One > or > > more of the Items in the next grid (that I just changed the Parent ID on > > with this Sub) has gotten the old Negative Autonumber back.. and
Of course > > the relation in Access is lost. > > > > I have been trying to figure out what rows are "changed" back to
the > > Negative ID and the only thing I have seen that's even remotly close, is > > that it's often is the Row in the datagrid that I have my cursor
on when I > > trigger the Save (Update on the dataset). But that' snot
completely true, > it > > also seems like the rows I have HAD selected and then Left also
the Get > > Negative ID back.. > > > > BUT.. here's the weird part.. it shouldn't matter what Rows I have > selected > > in the grids.. since the RowUpdated happens AFTER all that.. so
I'm > > completely Confused right now. > > > > To me it seems like even though the RowUpdated Sub is working alright when > > stepping thru it, some of the Items in the DataTable that I set
the New > > ParentID on, changes back after that... > > > > I know it's hard to explain this problem... > > > > PLEASE HELP!!! > > > > /Lars Netzel > > > > > > > > > > > > > > > > > > > > > >
Did'nt work... still hade the selected Row in the datagrid getting the
negativ value saved in the FK field.
now we bypassed by saving everything in the database with the wrok,
negative, FK values and then ww saved the real values in an Array and then
looped thru and updated the database manually.. sort of Timepressure here!
/lars
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> skrev i meddelandet
news:eK**************@TK2MSFTNGP09.phx.gbl... Lars, When you define the ForeignKeyConstraint (part of the DataRelation) you
need to set the ForeignKeyConstraint.UpdateRule to Rule.Cascade.
This will cause the child rows FK field to be updated to the parent row PK field when the DataSet.Update command returns the PK from the database.
As OHM has stated, the DataSet will largely take care of all the update on both the Child & Parent for you. You need to be certain that you define
the DataSet correctly is the Rub!
If you are only defining the DataRelation, you can use DataRelation.ChildKeyConstraint to retrieve the ForeignKeyConstraint
object that was created as part of the DataRelation.
If I didn't the other day, I would strongly recommend you review the relevant chapters in Sceppa's book!
For a good tutorial on ADO.NET as well as a good desk reference once you know ADO.NET see David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS press.
Hope this helps Jay
"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message news:uE*************@TK2MSFTNGP09.phx.gbl... Tried that, gave the same result so the relations actually worked but
some rows still got the Wrong Foregn Key when written to the databasen...
which means the Negativ Foregin key that the Dataset Generated for the Parent Table.
So I'm thinking it must be cause of something else.. or?
What about that it happens to the row that is selected in the Grid...
any ideas why it happens to that one?
I have checked to see if there are any other events triggred (like Position Changed) and it was but those are handled with a Global Variable and
they don't do anything.. so I'm sure that the Save I do and all the Updates
are not interfreered by any other code I have written somewhere else... I hope...
IT's really really frustrating, don't know where to turn anymore
really... and I really really need it done by today..
I Appiciate any help I can get here!
/Lars
"One Handed Man ( OHM#)" <news.microsoft.com> skrev i meddelandet news:%2****************@tk2msftngp13.phx.gbl... How have you got these relationships defined?
You can create a relation in the dataset and bind the Details grid to
this, that way it should work.
Regards OHM (Terry Burns) "Lars Netzel" <[stop_spam]@host.topdomain> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... > The PK is not the problem... it's the ParentID (foreign key) column
in the > Next table that's the problem.. which does not get the "new" ID from > access... > > So that's why I use the code to Catch the New ID given by Access in the > RowUpdated Event.. and then use ID to set as the Foregin Key in the next > table.. BUT here's where the troubles comes.. > > Some of the Rows that I "manually" set the foregin key on are fine, but the > row that is selected in the grid... for some reason get'äs the Negative > Foreign key value back before it's saved.. > > /Lars > > "One Handed Man ( OHM#)" <news.microsoft.com> skrev i meddelandet > news:%2****************@TK2MSFTNGP11.phx.gbl... > > You dont need any of this code. > > > > Lets say you add some records right ?,, they will have negative
PK's on > the > > Grid, once you run an update to the datasource, these will be assigned new > > positive ID's providing your Acccess Corresponding PK is Autoincremented > in > > the design. > > > > You can prove this. > > > > 1.) Create a table with two fields in it. One being the ID (
Primary key ) > > and set this to Autoincrement in Access. > > > > 2.) Put a grid on a form and bind the grid to the
dataset.datatable. > > > > 3.) Put the following code in the Load event of the form > > Me.DataSet11.Tables(0).Columns(0).AutoIncrementSee d = -1 > > Me.DataSet11.Tables(0).Columns(0).AutoIncrementSte p = -1 > > Me.OleDbDataAdapter1.Fill(Me.DataSet11) > > > > 4.) Create two buttons one for Fill and One for Update put the
code in for > > that. > > 5.) Create four entries, ( see the negative keys ). > > 6.) Click the Update and then Load. > > 7.) Bingo Your four new records all have numbers 1-4 for their PK. > > 8.) Updating the data in those non PK keys does not affect the PK, try it. > > > > > > HTH - OHM ( Terry Burns ) > > > > > > > > "Lars Netzel" <[stop_spam]@host.topdomain> wrote in message > > news:uH**************@TK2MSFTNGP09.phx.gbl... > > > A little background: > > > > > > I use three Datagrids that are in a child parent relation. > > > > > > I Use Negative Autoincrement on the the DataTables and that's workning > > nice. > > > > > > My problem is when I Update these grid and write to the database and I > set > > > the new Primary Keys and related Fields to the new asigned atuonumbers > in > > > the Access. > > > > > > The following Sub is the RowUpdated for the TopGrid's Adapter
that will > > get > > > the new ID and then set that as a ParentID in Datatable for the
the Next > > > Grid. > > > > > > > > >
'--------------------------------------------------------------------------- > > >
-------------------------------------------------------------------------- > > -- > > ------------------------------------------------------------------------ > > > > > > Private Sub adpProjParts_RowUpdated(ByVal sender As Object,
ByVal e As > > > System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles > > adpProjParts.RowUpdated > > > > > > If e.StatementType = StatementType.Insert Then > > > > > > Dim cmd As New OleDb.OleDbCommand("SELECT @@IDENTITY", > > e.Command.Connection) > > > > > > Dim OldId As Long = e.Row()("PRP_ID") 'This is primary key > > > > > > Dim NewID As Long = cmd.ExecuteScalar 'This is the New
PrimaryKey ID > > > > > > CopyDataViews() > > > > > > e.Row()("PRP_ID") = NewID > > > > > > e.Row().AcceptChanges() > > > > > > Me.dvProjCodes_COPY.RowFilter = Nothing > > > > > > Me.dvProjCodes_COPY.RowFilter = "prco_prpid=" & OldId > > > > > > Dim I As Long > > > > > > Dim alRows As New ArrayList > > > > > > Dim drvRowIter As DataRowView > > > > > > For I = Me.dvProjCodes_COPY.Count - 1 To 0 Step -1 > > > > > > alRows.Add(Me.dvProjCodes_COPY.Item(I)) > > > > > > Next > > > > > > Me.dvProjCodes_COPY.RowFilter = Nothing > > > > > > m_bIsSaving = True > > > > > > For Each drvRowIter In alRows > > > > > > drvRowIter.Row("prco_prpid") = NewID > > > > > > Next > > > > > > m_bIsSaving = False > > > > > > End If > > > > > > End Sub > > > > > > > > >
'--------------------------------------------------------------------------- > > > -------------------------- > > > > > > If I debug this Sub, everythign is fine and I everything seems
to get > the > > > right IDs when stepping thru it. BUT when I later check the database, > One > > or > > > more of the Items in the next grid (that I just changed the
Parent ID on > > > with this Sub) has gotten the old Negative Autonumber back.. and Of > course > > > the relation in Access is lost. > > > > > > I have been trying to figure out what rows are "changed" back to the > > > Negative ID and the only thing I have seen that's even remotly
close, is > > > that it's often is the Row in the datagrid that I have my cursor on when > I > > > trigger the Save (Update on the dataset). But that' snot completely > true, > > it > > > also seems like the rows I have HAD selected and then Left also the Get > > > Negative ID back.. > > > > > > BUT.. here's the weird part.. it shouldn't matter what Rows I
have > > selected > > > in the grids.. since the RowUpdated happens AFTER all that.. so
I'm > > > completely Confused right now. > > > > > > To me it seems like even though the RowUpdated Sub is working
alright > when > > > stepping thru it, some of the Items in the DataTable that I set the New > > > ParentID on, changes back after that... > > > > > > I know it's hard to explain this problem... > > > > > > PLEASE HELP!!! > > > > > > /Lars Netzel > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Lars,
This is NOT that difficult! It should "just work"! (It "just works" for me!
:-))
How are you creating the DataSet?
How are you creating the DataRelation?
Are you calling DataAdapter.Update on the Parent before you call
DataAdapter.Update on the children? sort of Timepressure here!
Understand. Sceppa's book fully explains the how & why to get it to work.
(It might be quicker to sit down with the book & review the relevant
chapter).
BTW: Reviewing Sceppa's book, the Rule.Cascade on the ForeignKeyConstraint
is the default.
Is this VS.NET 2002, VS.NET 2003, or VS.NET 2005 (the Whidbey preview)?
Hope this helps
Jay
"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:OA*************@TK2MSFTNGP10.phx.gbl... Did'nt work... still hade the selected Row in the datagrid getting the negativ value saved in the FK field.
now we bypassed by saving everything in the database with the wrok, negative, FK values and then ww saved the real values in an Array and then looped thru and updated the database manually.. sort of Timepressure here!
/lars
<<snip>>
This is the first time I have seen the shell of your cool composure eroded.
:-)
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eO**************@tk2msftngp13.phx.gbl... Lars, This is NOT that difficult! It should "just work"! (It "just works" for
me! :-))
How are you creating the DataSet? How are you creating the DataRelation?
Are you calling DataAdapter.Update on the Parent before you call DataAdapter.Update on the children?
sort of Timepressure here! Understand. Sceppa's book fully explains the how & why to get it to work. (It might be quicker to sit down with the book & review the relevant chapter).
BTW: Reviewing Sceppa's book, the Rule.Cascade on the ForeignKeyConstraint is the default.
Is this VS.NET 2002, VS.NET 2003, or VS.NET 2005 (the Whidbey preview)?
Hope this helps Jay
"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message news:OA*************@TK2MSFTNGP10.phx.gbl... Did'nt work... still hade the selected Row in the datagrid getting the negativ value saved in the FK field.
now we bypassed by saving everything in the database with the wrok, negative, FK values and then ww saved the real values in an Array and
then looped thru and updated the database manually.. sort of Timepressure
here! /lars <<snip>>
OHM,
I didn't think I was showing erosion as much as attempting to "walking
softly with a big stick" ;-)
For some reason Lars is having trouble with this, and I don't see that this
is that difficult, especially if you read Sceppa's book, as Sceppa IMHO
provides a clear explanation of what is going on. Now if Lars was
implementing IBindingList itself, I could see Lars having problems as
IBindingList is a very interesting interface to FULLY implement...
I suspect there is something simply in Lars code that he is not telling us
as to why its not working for him...
Just a thought
Jay
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:ev**************@tk2msftngp13.phx.gbl... This is the first time I have seen the shell of your cool composure
eroded. :-)
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
<<snip>>
Yeah, I thinks its one of those things, if you were there at the pc you
would probably spot it right away.
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Ob**************@TK2MSFTNGP12.phx.gbl... OHM, I didn't think I was showing erosion as much as attempting to "walking softly with a big stick" ;-)
For some reason Lars is having trouble with this, and I don't see that
this is that difficult, especially if you read Sceppa's book, as Sceppa IMHO provides a clear explanation of what is going on. Now if Lars was implementing IBindingList itself, I could see Lars having problems as IBindingList is a very interesting interface to FULLY implement...
I suspect there is something simply in Lars code that he is not telling us as to why its not working for him...
Just a thought Jay
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:ev**************@tk2msftngp13.phx.gbl... This is the first time I have seen the shell of your cool composure eroded. :-)
--
OHM ( Terry Burns ) . . . One-Handed-Man . . .
<<snip>>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bill C. |
last post by:
Hi,
I've got a simple console app that just reads an XML file into a DataSet
then prints out a description of each table in the DataSet, including
column names and row values for each column. ...
|
by: Geraldine Hobley |
last post by:
hello,
I have put thisup b4, but I think that people have misunderstood the problem, so I will make it clearer.
I have a problem updating a dataset that is bound to a datagrid.
The code that I...
|
by: jaYPee |
last post by:
does anyone experienced slowness when updating a dataset using
AcceptChanges?
when calling this code it takes many seconds to update the database
SqlDataAdapter1.Update(DsStudentCourse1)...
|
by: Niels Jensen |
last post by:
I have a some code which imports information from a text file to a dataset.
Depending op what is being extracted from the text file, the dataset has 5
tables which can be written to. During this...
|
by: Geoff |
last post by:
Hi
I'm hoping somebody can help me with the following problem that has occurred
to me.
Suppose I have two tables in an SQL Server database. Let's call these tables
A and B. Assume that A has...
|
by: susan.f.barrett |
last post by:
Hi,
Despite me being able to type the following in to SQL Server and it
updating 1 row:
> updatestockcategory 1093, 839
In my code, it is not updating any rows.
dataSet = new DataSet();
|
by: mike11d11 |
last post by:
I'm trying to create an application that will have multiple users
working off a table on a SQL server. Since multi users will be
updating different records at any given moment, how can i get those...
|
by: OldStd |
last post by:
Updating data using 2 data sets
I am having some problems in updating the database using two datasets as suggested by someone.
1. Data is displayed in a data grid from a dataset generated using...
|
by: jonbartlam |
last post by:
Hi There
I'm not sure what exactly is going wrong here. I'm writing an application that retreives a table from a database (tbl_internalfaults) and updates it. (Actually, just the status column will...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |