Re: User changing key value

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




<easoftware@xxxxxxxxx> wrote in message
news:1174886500.008839.301270@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am using VB.Net 2003. I have an Access database with two tables,
Parent and Child. The data is displayed in grids, and when the user
scrolls through the Parent grid, just the related Child data shows in
the Child grid. Simple. Works great.

The user wants to be able to change the value in the primary key of
the Parent table. I set up a form for this, and the forms does all
the error checking to make sure the new key values does not already
exist in the Parent table.

I have a Private var:

Private myBm As BindingManagerBase

My Form.Load event is

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.OleDbDataAdapter1.Fill(Me.DataSet11,
Me.DataSet11.Parent.TableName)
Me.OleDbDataAdapter2.Fill(Me.DataSet11,
Me.DataSet11.Child.TableName)
MyBm = BindingContext(Me.DataSet11,
Me.DataSet11.Parent.TableName)
End Sub

After the user has entered a new valid primary key value, I assign it
with:

Dim aRow As DataRow = CType(myBm.Current, DataRowView).Row
aRow("MyKey") = NewKeyValue

All this works fine, but when I assign the new key value, the rows in
the Child grid (linked to the old key value) disappear. If I change
rows in the Parent grid, and then return to the row with the new key
value, then the rows in the Child grid (the ones linked to the old key
value, and now the new key value) reappear. I have confirmed the
values in the linked column in the Child table are updated to the new
key, by having the linked column displayed in the Child grid.

It seams the Child grid does not see the new value of the key field.
I have tried

Dim aRow As DataRow = CType(myBm.Current, DataRowView).Row
aRow("MyKey") = NewKeyValue
myBM.EndCurrentEdit()

but it does not make the fix the problem. How can I make the linked
rows in the Child have their linked key value updated, and remain
being displayed, without having to scroll off and back onto the row in
the Parent grid?

Thanks for any help


Users should not be able to change primary key values!
Allowing them to do so, just begs for data integrity problems. I assume you
are using a natural primary key, thus leading to the request. I would
suggest for the table in question, that you use an artificial primary key (a
sequence, or autonumber in AccessSpeak) and make the field the user wants to
change a non-key field.


.



Relevant Pages

  • User changing key value
    ... Parent and Child. ... scrolls through the Parent grid, just the related Child data shows in ... the Child grid. ...
    (microsoft.public.vsnet.general)
  • Re: CurrencyManager Position issue
    ... Our grid is a custom grid, ... But, if we tie the current row to the CurrencyManager, a current row of -1 ... displayed in the child table if the first parent row has child records. ... then you want to be showing a selection in the parent ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Edit Data using MSFlexgrid
    ... Child Form to requery with the Child records linked to the current Parent ... I am using the code in the Fom_Current of the ParentForm, ... If you talking about the very last one, the grid on the left side actually ... I have another grid on the right that display multiple rows from the left ...
    (microsoft.public.access.formscoding)
  • (another) datarelation datagrid question
    ... in a manner described best by "How to Display Child Table Rows as a Column ... that i would like bound to the final grid. ... inside that loop i loop thru the child table and add the data from the ... look exactly as i want and as a bonus it filters parent records without ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DataGrid sort
    ... Now when you change rows in your parent grid, ... > change out the child grid contents and any existing child sort will be lost. ... >> I had high hopes for this solution, but the child table DataGrid remains ...
    (microsoft.public.dotnet.framework.windowsforms)