Board index » off-topic » Nested Datasets and Master/Detail
Douglas Burger
Delphi Developer |
Nested Datasets and Master/Detail2006-07-08 06:53:10 AM off-topic14 Well, I hate being yet another poster on what seems like a common problem, but I've pored over the books, usenet, qc, and help, plus I've tried many things from the minimum theoretically necessary steps to the maximum possible things I can think of, and I can't get what should be a simple thing to work. I'm probably missing something simple that's obvious only when you know about it. Essentially, I'm trying to recreate the simple examples straight out of the books, without success. In a nutshell, I'm attempting to setup a Master/Detail edit form using two TClientDataSets in a nested-dataset relationship through a TDataSetProvider to two BDE TQueries linked with a TDataSource in a master/detail parameterized link. I'm using Delphi 6 Update Pack 2 with everything on a single form. No 3- tier. My MIDAS.DLL file is 293,888 bytes, dated 2/15/2002. Problem: Post a new record to the master dataset causes "Key Violation" I can scroll through the master records and the detail grid shows the matching records. The record display works. When I add a record to the master dataset and post, I get "Key violation". No ApplyUpdates has happened. The error happens in the simple "Post". If unlink the detail datasets so that the master table becomes a single-table update, I can scroll, add, delete, applyupdates, do everything as expected. Adding in the nested dataset is what seems to break things. Problem2: Post a new record to the detail dataset causes "No corresponding master record found" If I try to add a record to the detail dataset and post, I get "No corresponding master record found." The grid shows that the link field in the detail matches the value shown in the master grid, so it seems that DataSnap "knows" which field is the linking field. Nothing I've tried changes these two error messages. At the current time, all datasets have persistent fields defined. The "key" fields have pfInKey set. The UpdateMode is UpWhereKeyOnly everywhere. The link field is the only field in the two datasets with the same name. All other fields have different names. The key fields are not editable by the user, and the NewRecord event generates decrementing negative numbers in the code for the pfInkey TFields. Details: Microsoft SQL Server 7. ODBC connection. The master table "key" (record) is auto-generated in an insert trigger and is defined in a unique index. (Call_Log) The detail table "key" (idperson_log) is an Identity property.and is not part of any index. (Person_Log) There is a Primary Key defined on two fields that are not marked pfInkey. I'm trying to get DataSnap work knowing only the "internal" integer key fields. Master TQuery (qryCall_Log) SELECT record, call_number, comments, personlogid FROM call_log WHERE call_number = :call_number Detail TQuery (qryPerson_Log) SELECT idperson_log, name_last, name_first, personlogid FROM person_log WHERE personlogid = :personlogid qryPerson_Log.DataSource = dsServerCall_Log (TDataSetProvider) provCall_Log.DataSet = qryCall_Log provCall_Log.options are all false. (TClientDataSet) cdsCall_Log.ProviderName = 'provCall_Log' There exists a persistent field in cdsCall_Log with the name 'qryPerson_Log' (TClientDataSet) cdsPerson_Log.DataSetField = cdsCall_LogqryPerson_Log There are a dsCall_Log and a dsOfficer_Log TDataSources on top of the CDSes. When the form is created, I perform: cdsCall_Log.FetchParams; cdsCall_Log.ParamByName('call_number').AsString := strCall_Number; cdsCall_Log.Open; The grids and data-aware controls show the expected data for both master and detail. I can scroll the master, and the detail data changes. I don't have a problem until I add a call_log record and post. The grid shows the "record" column of the added record with the code-generated numbers, -1, -2, etc. Any help will be appreciated. I had hoped to get the benefits of TClientDataSet with less frustration than this. Doug |