🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #825

Re: Setting Query Parameters to a NULL string

#825
From: Ondrej Gratz
Date: Fri, 27 May 2005 05:51
64 lines
3448 bytes
Hi Stephen,
I'm sorry, I didn't try it. Now I remember...some time ago "Parameter 
'MyField' not found" exception has been the reason why I use 
StringReplace function :-) instead of parameters.
I recommended quotes because I thought the SQL commmand would be wrong 
when you used NULL values ...INSERT INTO myTable (MyField, field2) 
VALUES (, )
I hope someone will give us better answer too.

Sincerely
Ondrej Gratz


Stephen Craig wrote:
> Hi Ondrej,
> Thanks for the reply
> 
> If I use quotes as you described (either single or double (\")) as follows
>     INSERT INTO myTable (MyField, field2) VALUES (':MyField', ':field2')
> and I attempt to set parameters using
>     qry->Parameters->ParamByName("MyField")->Value = "";
> Then I get the error
>     Parameter 'MyField' not found
> 
> Interestingly, if I revert back to
> 
>     INSERT INTO myTable (MyField, field2) VALUES (:MyField, :field2)
> and set the parameter to some string and then set it to a NULL then it all
> is ok.  ie...
>     qry->Parameters->ParamByName("MyField")->Value = "dummy";
>     qry->Parameters->ParamByName("MyField")->Value = "";
> This works perfectly
> 
> I can only imagine that the first assignment is setting some parameter
> property.  Initially I thought that this would be the DataType property.
> But setting this to ftString prior to the NULL assignment ie...
>       qry->Parameters->ParamByName("MyField")->DataType = ftString;
> 
>       qry->Parameters->ParamByName("MyField")->Value = "";
> makes no difference. I get the same old exception ...
>      [Microsoft][ODBC Microsoft Access Driver]Invalid precision value.
> 
> I also tried setting the parameter Attributes to paNullable
>       qry->Parameters->ParamByName("MyField")->Attributes << paNullable;
> Still get exception
> 
> I think I'll just have to use the dummy assignment, unless anyone can come
> up with a better answer
> 
> Steve
> 
> "Ondrej Gratz" <gratzo@atlas.cz> wrote in message
> news:4294958b@newsgroups.borland.com...
> 
>>Enclose string parameters in quotation marks...
>>
>>INSERT INTO myTable (MyField, field2) VALUES (":MyField", ":field2")
>>
>>Sincerely
>>Ondrej Gratz
>>
> 
> 
> 
Technical Details
Message-ID: <4296b54c@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <428c1ce6$1@newsgroups.borland.com> <4294958b@newsgroups.borland.com> <42966bb3$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,5acac13d62ebf4f7
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Fri, 27 May 2005 07:51:09 +0200
From: Ondrej Gratz <gratzo@atlas.cz>
User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Re: Setting Query Parameters to a NULL string
References: <428c1ce6$1@newsgroups.borland.com> <4294958b@newsgroups.borland.com> <42966bb3$1@newsgroups.borland.com>
In-Reply-To: <42966bb3$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit
X-Antivirus: avast! (VPS 0521-3, 26.05.2005), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 85.160.64.147
Message-ID: <4296b54c@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1117173068 85.160.64.147 (26 May 2005 22:51:08 -0700)
Lines: 64
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail