client dataset master-detail indexes

I have three ado datasets with 3 master-detail levels which create 3 client datasets displayed in a form with 2 grids. Since the unique ID's are integer a table for keeping the indexes must be used (I think). Can you tell me (and show me the code) which is the optimum way for adding records in the three levels and post data?

Manolis Perrakis