Hello Everyone,
I have a situation that is driving me crazy - I hope someone out there can
help.
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:
Queries
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 =
:ApartmentID'
qry_ApartmentFee.RequestLive := true;
Fields
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:
var
i: integer;
lRelationField: TField;
begin
for i := 0 to qry_ApartmentFee.FieldCount - 1 do begin
lRelationField :=
qry_Apartment.FindField(qry_ApartmentFee.Fields[i].FieldName);
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;
qry_ApartmentFee.Fields[i].Assign(lRelationField);
end; //if assigned
end; //fields loop
end;
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...
TIA,
John Sklavounos