[Delphi] Problem z NULLem w Edit.text

0

Witam
Mam aplikacje w delphi, przy dodawaniu nowych rekordów chce mieć jedno pole puste. Chce miec puste pole model (zeby puzniej go uzupelnic)
Gdu naciskam przycis zapisz wyskakuje mi taki błąd:
[Sybase][ODBC Driver][Adaptive Server Anywhere]Integrity constraint violation: Invalid value for column 'model' in table 'aaa'
Napisałem taką procedure:

procedure TB_dodaj.BitBtn2Click(Sender: TObject);
begin
DataModule1.ADOQuery3.Close;
with DataModule1.ADOQuery3 do
begin

  Parameters.Clear;
  with sql do
    begin
      Clear;
      Add('INSERT INTO aaa(id_a, nazwa, typ, model) ');
      Add('VALUES(:ida,:nazwa,:typ,:model)');
    end;
    Parameters.ParamByName('ida').Value:=Edit1.Text;
    Parameters.ParamByName('nazwa').Value:=Edit2.Text;
    Parameters.ParamByName('typ').Value:=Edit3.Text;
    
    <span style="color: red">IF (Edit1.Text <> NULL) THEN
    Parameters.ParamByName('model').Value:=Edit4.Text
    ELSE
    Parameters.ParamByName('model').Value:='NULL';
</span> end; DataModule1.ADOQuery3.ExecSQL; DataModule1.ADOQuery3.Close; with DataModule1.ADOQuery3 do begin Parameters.Clear; with sql do begin Clear; Add('SELECT * '); Add('FROM aaa'); end; end; DataModule1.ADOQuery3.Open; end;

Jak by ktoś wiedział dlaczego mi to nie działa to proszę o pomoc
Tomek

0

Czym jest NULL w wyrażeniu ?

if Edit1.Text <> NULL then

Dla stringów odpowiednikiem NULL jest pusty string, czyli '', czyli

if Edit1.Text <> '' then .Value := Edit4.Text else .Value := 'NULL';
0

Zmieniłem na:

IF (Edit4.Text <> '') THEN
Parameters.ParamByName('model').Value:=Edit4.Text
ELSE
Parameters.ParamByName('model').Value:='NULL';

Teraz wysakkujem mi komunikat
Cannot convert NULL to a INT

0

Juz mam :)

IF (Edit4.Text <> '') THEN
Parameters.ParamByName('model').Value:=Edit4.Text
ELSE
Parameters.ParamByName('model').Value:=NULL;

1 użytkowników online, w tym zalogowanych: 0, gości: 1