delphi - Database master-detail relationship - How to prevent entering non existent value to master table? -


in master detail relationship

procedure tdatamodule.table1afterscroll(dataset: tdataset); begin     if table1.fieldbyname('unit_id').asstring <> ''     begin         query1.close;         query1.sql.clear;          query1.sql.text:= 'select * table2 unit_id = ' +         table1.fieldbyname('unit_id').asstring;          query1.open;     end; 

how can make sure when editing (and saving) query1 results not enter nonexistent unit_id?

i want unit_id able changed, want make sure not enter unit_id not exist.

afterscroll not right event use beforepost instead in way:

procedure tdatamodule.table1beforepost(dataset: tdataset); begin     if table1.fieldbyname('unit_id').asstring <> ''     begin         query1.close;         query1.sql.text:= 'select unit_id table2 unit_id = ' +             table1.fieldbyname('unit_id').asstring;         query1.open;         if query1.recordcount=0 abort; //so if there not such                                             // unit_id don't save     end; end; 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -