Page 1 of 1

empty DBEdit in VARCHAR column

Posted: Thu 23 Apr 2009 23:09
by Frega
hello, im starting with devart mysql component for delphi and im having a problem with empty dbedits, here it goes:


in the Client Inserting form i have a DBEdit linked to column email by a MyQuery -> DataSource -> DBEdit


I need that MyQuery pass the value null to the database and not a blank value, because this field (email) is set 'not null' , and the blank value sent by MyQuery bypasses the blockage of 'not null' of the database..



(In my form i have a button register, when i click it, and a required field is not supplied, MySQL return a error and the button have a error handler, that block user to finish the register, but the database only return a error when i sent a NULL value, but MyQuery is sending as Blank value ' ')



how to send a null value to the database when the dbedit is not supplied?




Sorry bad english
thanks...

Posted: Fri 24 Apr 2009 07:08
by Dimon
To solve this problem you may handle the TMyQuery.BeforeUpdateExecute event and check the set value of the 'email' field, like this:

Code: Select all

  if Params.FindParam('email')  nil then
    if Params.ParamByName('email').AsString = '' then
      Params.ParamByName('email').Clear;

Posted: Fri 24 Apr 2009 07:41
by jkuiper
Set your default value in your table to ''. When the field is NULL, MySQL wil use the default value.