Board index » cppbuilder » How to send NULL in a TField to database?
Reddog
![]() CBuilder Developer |
How to send NULL in a TField to database?2005-12-23 02:20:08 AM cppbuilder89 Hi all, I want to send a NULL in a TField, (called 'update' and defined as a column of type TIMESTAMP - I am using MySQL) - this should result in the current MySQL server timestamp being entered into the table. From the MySQL command prompt this is fine ie I can either ignore the column or set it to NULL and it is timestamped in the table ok. But I cannot get the BCB TField to accept a NULL, I get EDatabaseError exception "Field 'update' must have a value". In the BeforePost event I removed the faRequired from the TTable DataSet attribute set, expecting BCB not to send the 'update' field, but although the removal works the result is still an exception, eg void resetRequired ( TDataSet *DataSet) { TFieldDef *fd = DataSet->FieldDefs->Find("update"); if ( fd) { if ( fd->Attributes.Contains(faRequired) ) { TFieldAttributes ss; ss << faRequired; fd->Attributes -= ss; } } } Any ideas on how to get BCB to either a) not send the field or b) to accept NULL? I am hoping that I have just missed a setting somewhere!!! Oh and by the way : 1) I do not want to remove the field from the BCB dataset as I want to see the value it contains when I refresh - thus indicating the last update of the record etc. 2) and I do not want to use a TQuery (ie not setting the 'update field) as this would entail SQL coding for each table with an 'update' field. Thanks, Reddog. |