DelphiFAQ Home Search:

How to set a NULL value through the VCL


comments1 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.


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?


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

  Query1 : TQuery;

  Query1.FieldByName('FIRST_NAME').AsString = 'noname';
  Query1.FieldByName('P_ID').Clear;  // set this field to NULL
You don't like the formatting? Check out SourceCoder then!
Content-type: text/html


2012-06-28, 10:01:07
Fábio from Brazil  



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: