[Winforms] Databinding and a Trigger...

E

E®!k \\/!sser

Hi all,
I am facing the following problem.
I have a Invoice form with a grid, the Invoice_details.
Now some data on the Invoice_Details form depend upon the data on the
Invoice grid. For example, on the Invoice_Details form is a combox and the
listed values differ for each (group of) customers.
As the whole application is datadriven, the changes on the Invoice form
needs to be written to the database before the Invoice_Details form is build
up.
So this code is called to write the changes to the database: (Before the
Invoice_Details form is opened)

this.Validate();
this.oBindingSource.EndEdit();
new SqlCommandBuilder(this.DaUpdate);
this.DaUpdate.Update(this.DtUpdate);
this.DtUpdate.AcceptChanges();

This works ok the first time it is called.
But when the user makes another change on the invoice form, after editing
the Invoice_Details, I get a concurrency exception. This has to do with a
trigger on the database table that updates a LastChanged_Date column on the
Invoice table on every time changes are written to the database. Removing
the trigger solves the problem, but you'll understand that is not the real
solution.

So I guess I'll have to update the datatable with the new values on the
database.

this.DaUpdate.Fill(this.DtUpdate);
this.oBindingSource.ResetBindings(false);

But this does not solve it: the problem remains.

Any comments on this are highly apreciated.


Erik
 
J

Jim Rand

I would just use a simple dataset containing both the invoice header and
invoice detail. Bind the form to header and the detail grid to the
relationship. The update button would send both the a header and the detail
to the database - hopefully within a transaction so you are either 100%
successful or you fail completely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top