Delphi .NET (2) Database (71) Delphi IDE (89) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
How to set a NULL value through the VCL
This article has not been rated yet. After reading, feel free to leave comments and rate it.
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; Query1.Post;
end | |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|