PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Master Detail InsertCommand

Reply

Master Detail InsertCommand

 
Thread Tools Rate Thread
Old 22-12-2006, 08:45 PM   #1
Santi
Guest
 
Posts: n/a
Default Master Detail InsertCommand


Hi,

I am developing an application that accesses a Foxpro database (.dbf
files) with two tables, the master table (customers) has a field (id)
which is primary key. The detail table (orders) has a primary key
formed by the fields: customerid, orderid. The order id is a not
automatic counter for every customer orders.

Ex:

CustomerID 1 - OrderID 1
CustomerID 1 - OrderID 2
CustomerID 2 - OrderID 1
CustomerID 2 - OrderID 1
CustomerID 2 - OrderID 2

I don't know how to build the InsertCommand for the Orders table. Those
are the problems I have:

- To know the order id I need to query the database before inserting.
Can I make an InsertCommand with two commands? The first queries the
database for orderid and the second inserts the record.
- I can not make a single query because I think Foxpro does not allow
sentences like this:
INSERT INTO orders (customerid, orderid) VALUES (1, SELECT
max(orderid)+1 WHERE customerid=1)

I suppose if I don't relay on InsertCommand and handle the insertions
myself I will have more control but I wanted to take advantage of
ado.net automatic updates with insertcommand.

Thank you very much!

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off