Updating the details in a master/detail scenario

Updating the details in a master/detail scenario

Post by Andrew Dave » Thu, 25 Apr 2002 09:25:11



Hi,

I figure that I'm probably not the first to ask this question, but *ed
if I could find an answer.

I have a dataset which take data from two adapters. I've defined a
relationship between the two tables and hence have set up a master/detail
scenario. The master control is a datagrid and the detail controls are a
bunch of text boxes.

My problem is this, I can detect and update the database with any changes
made in the datagrid (master), but I can't do it for any of the detail
records. I know that the dataset is being updated as when I make a change
(say someones address) and move to another record and come back the change
is present. But I can't seem to find the right way to tell the database to
get updated.

Any help with this is would be tops

Andy.

 
 
 

Updating the details in a master/detail scenario

Post by Kathleen Dollar » Fri, 26 Apr 2002 00:28:01


Andy,

Quote:> My problem is this, I can detect and update the database with any changes
> made in the datagrid (master), but I can't do it for any of the detail
> records. I know that the dataset is being updated as when I make a change
> (say someones address) and move to another record and come back the change
> is present. But I can't seem to find the right way to tell the database to
> get updated.

I am guessing that you are having AcceptChanges run on your dataset after
the first update. Try doing the updates against the individual tables
instead of the dataset.

da.Update(dataset.Tables(TableName))

Kathleen

 
 
 

Updating the details in a master/detail scenario

Post by Phil Tod » Sat, 04 May 2002 21:17:13


I have also had problems with the HasChanges Dataset method. I have a
similar situation, my master table is displayed in databound textboxes with
detail table in datagrid. For some reason changing the value in a databound
control changes the record in the dataset but the HasChanges still returns
false.

I ended up copying code from a form created using the DataForm Wizard. This
generated code uses the GetChanges method of the dataset to create a new
dataset. It then checks if the new dataset is nothing. If it is not nothing
then changes have taken place and the db is updated. In this way they are
avoiding using the HasChanges method. Seems to suggest to me that Microsoft
is aware of this behaviour.

This is a copy of the code:

'Create a new dataset to hold the changes that have been made to the main
dataset.

Dim objDataSetChanges As Dataset = New Dataset ()

'Stop any current edits.

Me.BindingContext(objAgreements, "tbl_NTAAgreements").EndCurrentEdit()

Me.BindingContext(objAgreements, "tbl_NTADrawDowns").EndCurrentEdit()

'Get the changes that have been made to the main dataset.

objDataSetChanges = CType(objAgreements.GetChanges, Dataset )

'Check to see if any changes have been made.

If (Not (objDataSetChanges) Is Nothing) Then

        ' do update

End If

Hope this helps....


Quote:> Hi,

> I figure that I'm probably not the first to ask this question, but
*ed
> if I could find an answer.

> I have a dataset which take data from two adapters. I've defined a
> relationship between the two tables and hence have set up a master/detail
> scenario. The master control is a datagrid and the detail controls are a
> bunch of text boxes.

> My problem is this, I can detect and update the database with any changes
> made in the datagrid (master), but I can't do it for any of the detail
> records. I know that the dataset is being updated as when I make a change
> (say someones address) and move to another record and come back the change
> is present. But I can't seem to find the right way to tell the database to
> get updated.

> Any help with this is would be tops

> Andy.