DelphiFAQ Home Search:
General :: Programming :: Delphi :: Database
Database development with Delphi. Includes issues with BDE, ADO and InterBase.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

How to set a NULL value through the VCL

Question:

I need to set a field in a record back to NULL (not an empty string or 0 for a numeric field).
I know I could run a SQL statement and do something like

'update customers set pid = NULL where cust_id=1234'

How can I do this within a TQuery using .Edit and .Post methods and TField instances to assign values?

Answer:

To set a field to NULL, you need to use the TField.Clear method. See the code below for an example.

var
   Query1 : TQuery;
 
 begin
   //..
   Query1.Edit;
   Query1.FieldByName('FIRST_NAME').AsString = 'noname';
   Query1.FieldByName('P_ID').Clear;  // set this field to NULL
   Query1.Post;
 end
You don't like the formatting? Check out SourceCoder then!
Generated 20:01:16 on Jul 16, 2018