Super Dave 123
Member
- Joined
- Sep 3, 2008
- Messages
- 19
- Programming Experience
- 1-3
Hello,
Here is my problem I need to resolve.
I am retrieving and editing data from the Customer and Order tables. The primary key in the Customer table is CustomerID and the foreign key in the Order table is CustomerID. The relationship between these tables is a one to many. I had created one ADO dataset to store these two tables. I also had created a data relation that joins both of these tables in the dataset. In addition to this, I had set the child key constraint for this relation to be cascade update. I had assigned this dataset to the Customer and Order grid controls with the Customer grid control located at the top of the form while the Order grid control is located at the bottom of the form.
When a person adds a customer record to the Customer grid control, the person would then add an order record in the Order grid control right after adding the new customer record. For the Order grid control to save the new order record in the database, I had to do the following:
1) use the data adapter to save the new customer record in the database so that I can get the auto number primary key field in the Customer table of the database to generate a primary key value for this new customer record
2) use the reset command to clear the entire dataset that was used by both grid controls
3) retrieve the data from the Customer and Order tables in the database and then place them in the same dataset that was cleared in the previous step
4) recreate the data relation that binds these two tables
5) clear the datasource for both grid controls
6) re-assign the Customer table in the dataset to the Customer grid control
7) re-assign the Order table and data relation to the Order grid control
8) program retrieves the CustomerID value for this new customer record in the Customer grid control
9) program than assigns this CustomerID value to the foreign key column in the Order grid control for the new order record. This is done when the person starts adding the new order record in the Order grid control.
Is there a shorter way of getting the new primary key value for the customer record rather than performing all of the nine steps as stated previously? That is, can I get the new primary key value for the new customer record and then have it assigned to the new order record without having to save the new customer record in the database?
Thanks.
Here is my problem I need to resolve.
I am retrieving and editing data from the Customer and Order tables. The primary key in the Customer table is CustomerID and the foreign key in the Order table is CustomerID. The relationship between these tables is a one to many. I had created one ADO dataset to store these two tables. I also had created a data relation that joins both of these tables in the dataset. In addition to this, I had set the child key constraint for this relation to be cascade update. I had assigned this dataset to the Customer and Order grid controls with the Customer grid control located at the top of the form while the Order grid control is located at the bottom of the form.
When a person adds a customer record to the Customer grid control, the person would then add an order record in the Order grid control right after adding the new customer record. For the Order grid control to save the new order record in the database, I had to do the following:
1) use the data adapter to save the new customer record in the database so that I can get the auto number primary key field in the Customer table of the database to generate a primary key value for this new customer record
2) use the reset command to clear the entire dataset that was used by both grid controls
3) retrieve the data from the Customer and Order tables in the database and then place them in the same dataset that was cleared in the previous step
4) recreate the data relation that binds these two tables
5) clear the datasource for both grid controls
6) re-assign the Customer table in the dataset to the Customer grid control
7) re-assign the Order table and data relation to the Order grid control
8) program retrieves the CustomerID value for this new customer record in the Customer grid control
9) program than assigns this CustomerID value to the foreign key column in the Order grid control for the new order record. This is done when the person starts adding the new order record in the Order grid control.
Is there a shorter way of getting the new primary key value for the customer record rather than performing all of the nine steps as stated previously? That is, can I get the new primary key value for the new customer record and then have it assigned to the new order record without having to save the new customer record in the database?
Thanks.