Board index » delphi » Master/Detail with tQuery/TUpdateSQL on MSSQL 2000 Server

Master/Detail with tQuery/TUpdateSQL on MSSQL 2000 Server

Hello Everyone,

I have a situation that is driving me crazy - I hope someone out there can

Database: MSSQL 2000 Server
Delphi: D5 all patches
BDE: 5.1.1
OS: Windows XP Pro SP 1

In MSSQL 2000 Server I have defined 2 tables as follows: (please excuse the
pseudo DDL)

Apartment Table:
ApartmentID char 36 Default (convert(varchar(36),newid()))
ApartmentName char 50
ApartmentAddress char 50
ApartmentCity char 50
ApartmentState char 2
ApartmentZip char 10

Apartment Fee Table:
ApartmentFeeID char 36 Default (convert(varchar(36),newid()))
ApartmentID char 36 (relation to Apartment Table)
ApartmentFeeName char 50
ApartmentFeeAmount money

On a data module, I have placed 2 tQueries, 2 tDataSources & 2 tUpdateSQL:

qry_Apartment, ds_Apartment, upd_Apartment, qry_ApartmentFee,
ds_ApartmentFee, upd_ApartmentFee

They are set up as follows:
qry_Apartment.AutoRefresh := true;
qry_Apartment.RequestLive := true;
qry_ApartmentFee.AutoRefresh := true;
qry_ApartmentFee.DataSource := ds_Apartment
qry_ApartmentFee.SQL := 'select * from ApartmentFee where ApartmentID =
qry_ApartmentFee.RequestLive := true;
qry_ApartmentApartmentID.AutoGenerateValue := arDefault
qry_ApartmentApartmentID.pfInKey := true;
qry_ApartmentFeeApartmentFeeID.AutoGenerateValue := arDefault
qry_ApartmentFeeApartmentFeeID.pfInKey := true;

On a form I have a DBNavigator, DBEdit boxes for all fields in qry_Apartment
and a DBGrid tied to qry_ApartmentFee.

In the OnNewRecord event of qry_ApartmentFee I have the following code:

  i: integer;
  lRelationField: TField;
    for i := 0 to qry_ApartmentFee.FieldCount - 1 do begin
      lRelationField :=
      if Assigned(lRelationField) then begin
        //This is to fill in the Master Key field if it's empty so we have a
valid relationship

        if lRelationField.IsNull
        and (lRelationField.DataType = ftString)
        and (lRelationField.Size = 36)
        and (qry_Apartment.State in [dsEdit, dsInsert]) then
            lRelationField.AsString := GenerateUniqueString;
      end; //if assigned
    end; //fields loop

All this works fine so far... the problem is that when I have an existing
set of data (an apartment record and some fee records) and try to insert a
new fee in the grid, I get the following error:  "Multiple records found,
but only one was expected.".  This does not happen when I am first entering
the records; although the behavior at that point is odd as well - after the
insert completes the inserted record is hidden with no errors and when I go
back to that record at a later time, it's there just fine.

Any help you can provide would really, really, really help me out...

John Sklavounos


Re:Master/Detail with tQuery/TUpdateSQL on MSSQL 2000 Server


  Check out and search on your error.  There
are a number of possibilities/solutions.

Good luck,

"John Sklavounos" <> wrote in message
> Hello Everyone,

> I have a situation that is driving me crazy - I hope someone out there can
> help.

Other Threads