Updating multiple source tables from a single datatable

G

Guest

H
I would like to select data from two (or more) source tables, and show the data in a grid where the data is in the same row of the grid. (Windows Forms

So, if we have a database with a company and an address table, like this
company: companyId, name, phone, fa
address: addressId, companyId, address, country, zipcod

The grid should have the fields from these two tables like this
Grid: name, phone, fax, address, country, zipcod

These fields should be in the same row, and the user should be able to edit and save changes

To get the data into one datatable, I made a query that joins the source tables and returns a datatable that is shown in the grid

The question I would like to ask is: "How do I update the source tables from this edited datatable

Thank you in advance
-Christia
 
S

SEA Software

How about if you create a query or a view and use it as if it was the data
table?

You just have to make sure that the primary keys are available, otherwise no
update is allowed.

--

Ori Millo
Solutions Consultant
SEA Software Ever After
http://www.s-e-a.com.au


Christian said:
Hi
I would like to select data from two (or more) source tables, and show the
data in a grid where the data is in the same row of the grid. (Windows
Forms)
So, if we have a database with a company and an address table, like this:
company: companyId, name, phone, fax
address: addressId, companyId, address, country, zipcode

The grid should have the fields from these two tables like this:
Grid: name, phone, fax, address, country, zipcode

These fields should be in the same row, and the user should be able to edit and save changes.

To get the data into one datatable, I made a query that joins the source
tables and returns a datatable that is shown in the grid.
 
G

Guest

I don't follow. How would a view help
The problem is, when I update one of the source tables, the rowstate property in the datatable changes to "unchanged", and then I can't update the second table. Only, say, 3 out of 8 fields were saved to the first table, and the remaining fields should be saved to the second table, but because of the "unchanged" rowstate, nothing is saved in the second update

Regards
Christian
 
W

William Ryan eMVP

Christian:

When you call update, each time a row is processed, AcceptChanges is called
on it. Anyway, I think you're going to have to make a copy of the table
before the update or manually loop through it yourself and fire the commands
simulating what is done by the datapter. There's no
AcceptChangesDuringUpdate or similar feature for updates.
Christian said:
I don't follow. How would a view help?
The problem is, when I update one of the source tables, the rowstate
property in the datatable changes to "unchanged", and then I can't update
the second table. Only, say, 3 out of 8 fields were saved to the first
table, and the remaining fields should be saved to the second table, but
because of the "unchanged" rowstate, nothing is saved in the second update.
 

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