Adding new records when databinding and using data relation win forms / data form wizard

Adding new records when databinding and using data relation win forms / data form wizard

Post by Develope » Wed, 18 Aug 2004 03:28:50


I have a dataset with two tables and a relation between them.
I have controls (textboxes, check boxes etc) on a windows form bound to
those data tables. Editing existing data and navigating
between records works fine. However when I try to add a new record, only the
master table is updated to the dataset (and eventually to the database).

I struggled with this problem for a while and then decided to check what
VS.NET data form wizard would generate in a similar situation.

So I did the following actions:
1) added dataform to windows app .Net project
2) connected to Northwind database (SQL server)
3) created a new dataset
4) selected Orders and Order Details tables
5) created a datarelation between Orders and Order Details -tables ( Orders
being the parent and Order Details the child).
6) chose all columns to be displayed from both tables
7) selected 'single record in individual controls'

The generated form works fine when editing existing data or navigating.
However when trying to add a new record,
the master portion of the order (ie. individual text boxes) has to be saved
prior to saving any Order Details rows. If the master portion isn't
saved, "ForeignKeyConstraint 'x' requires the child key values (eg. 11088)
to exist in the parent table. Do you want to correct the value?" message
is displayed. ['x'= name of the datarelation in step 5]. So it's not
possible to fill in all the necessary fields and then just hit 'update' to
save the new order.
Interestingly the OrderID is populated correctly in the datagrid with or
without saving the master portion?!

So how should the wizard generated code be amended to allow users to save an
order by hitting update button just once?

Any thoughts and/or pointers would be appreciated.

Thanking in advance!

1. Adding new record to form using the field data from current form

2. Copy data from one form to another and create a new record to add data

Ok, here's the outline:

I have a form called frmOrders, which has a subform (frmOrderDetails)
and another form called frmProducts.

In frmOrderDetails, when I double-click on a field called ProdDescrip
it opens frmProducts, which gives me a product list and it's prices.
When I double-click a product, automatically add the products to the
frmOrderDetails fields ProdDescrip and UnitPrice. But I can't save the
record in frmOrderDetails and move to a new one so I can add more

This is the code on frmProducts

Private Sub ProductName_DblClick(Cancel As Integer)

Forms![frmOrders]![frmOrderDetails]![ProdDescrip] = [ProductName]
Forms![frmOrders]![frmOrderDetails]![UnitPrice] = [ProductPrice]

I've already tried with SaveRecord, GetFocus, and nothing seems to

Any suggestions?

3. Data Form Wizard - Data not being returned to the form????

4. Using recordsetclone when only allowing new records to be added (Form Property Data Entry = yes)

5. Adding new record to form using the field data from current fo

6. Form jumps to previous record when data is added to form

7. Open New Record in Form B with Data from Form A

8. retrieving textbox form data from an ENCTYPE=multipart/form-data form

9. Copy form data to new insert record form

10. Updating Data In One Form Using Data Entered In Another Form

11. Create a form in excel so I can enter data using Data>Form

12. Add record Form, close and go to new record in other form

13. Using popup form to add data to main form.

14. Using Add button to capture data in form and recreate form

15. My data entry form.... isn't adding new data?