The following situation comes up quite frequently in an
application I am designing, and I just want to make sure I
am not missing something.
The situation: A Windows form opens and fills a strongly
typed datatable with one record from Table 1 (the
parent). The user can then open a second form to insert
new records into Table 2 (the child) that relate to the
record in Table 1. The second form also uses a
dataadapter to fill a strongly typed datatable. Overall,
the scenario is similar to a Customers > Orders
relationship.
Everything is easy if Table 2 contains records related to
Table 1 when its 'child' datatable is filled. I can then
insert new records, update existing ones, etc with no
problem. The trouble comes when there are NO pre-existing
records in Table 2 (ie no orders for a particular
customer) when the second datatable tries to fill. In
this case, what is the best strategy for getting new Table
2 records to the database? What I have been doing is
using the sql command that corresponds to my insert sproc,
setting values for all of the parameters, and then using
execute nonquery. This works just fine, but does not seem
to elegant. Before I continue using this method in
similar circumstances, I wanted to know if someone had
some other suggestions. Thanks.
John