views:

447

answers:

1

In a nutshell: I have a DataSet with multiple DataTables inside, which are connected via multiple DataRelations. I've created a form using databinding on this DataSet, and you could say it is pretty complex.

The scenarios is next: the main purpose of the form is the insertion of a new record. For it to be inserted, various parent-child relations must be set. It all works fine with the databinding, but the problem is next: when user wants to enter a new "child" for one-of-those parent-child relations, new form opens, he enters it, yada yada yada, - and it works. Trouble is - how should I get that new data back to the original form, to appear in parent-child combobox?

One way I know of, is to refresh the entire form; but I am looking for a solution to refresh just the DataTable containing that data. I've tried getting a new DataTable with fresh data from DB, and merging it with DataTable in DataSet, but it doesn't work: "A child row has multiple parents" exception is thrown:

// basically just a Select * using dataadapter,
// nothing programmatically added 
DataTable table = tableModule.GetPlainTable(); 
existingDataSet.Tables["tableName"].Merge(table);

The equivalent example of what I'm trying to do is to have a Order form, with Customer combobox on it. On the right of the combobox, there is a "add" button that opens a new "Add customer" form. Just to mention (maybe it is relevant), inside the DB, "Customers" table is in relation with the "Cities" table, and that data is linked in databindning on the Orders form as well...

EDIT: one solution I can think of is to "manually" loop throughout the new DataTable, and find all rows that are not in the original DataTable inside DataSet, but I'm not sure this would work either ...

Any help / suggestion / explanation / push in the right direction would be greatly appreciated :)

A: 

Well, i kind of solved the problem with manual row copy upon insertion in second form... I have created an event with object collection (row item array), and in first form registered a handler on that event, in which I manually add the new row via:

data.Tables["tableName"].Rows.Add(e.RowItems);

after which I call AcceptChanges() on that row to make its state Unchanged, rather than Added...

This solution, although quick-and-dirty, works. The problem is, I think there is a better, more "databinding" philosophy oriented one... :=)

Sapphire