Page 1 of 1

Inserting NULL

Posted: Mon 21 Nov 2016 13:22
by bdkacz
Hi.

How to insert NULL as parameter for TMSSQL ?

For example I have code like that :

Code: Select all

if (some if statement)  then
aqZapisz.ParamByName('p1').AsInteger := 1
else
aqZapisz.ParamByName('p1').Value := Variants.null

but I receive error that I need to use convert to insert nulll..
The column is defnded as int type with allow nulls

Re: Inserting NULL

Posted: Tue 22 Nov 2016 10:14
by asc
In C++ works something like:

Code: Select all

void SetNullParam(
    TMSQuery * query,
    String const & parameterName,
    TFieldType parameterTyp)
{
    query->ParamByName(parameterName)->Clear();
    query->ParamByName(parameterName)->Bound = true;
    query->ParamByName(parameterName)->DataType = parameterTyp;
}

Re: Inserting NULL

Posted: Tue 22 Nov 2016 10:29
by bdkacz
In Delphi also works great,thank you

Re: Inserting NULL

Posted: Wed 23 Nov 2016 09:26
by azyk
Calling the Clear method and value setting to the DataType property to ftInteger for dataset parameter is a correct way to set a NULL value to the int parameter.