Article View: borland.public.cppbuilder.database.ado
Article #780Re: SQL Parameters not cleared
From: Robert J Emmons
Date: Wed, 13 Apr 2005 19:32
Date: Wed, 13 Apr 2005 19:32
72 lines
3738 bytes
3738 bytes
James Peterson wrote:
> try adding a Qry->Close(); at the top and Qry->Open(); at the bottom. My
> guess is that the query isn't getting clear properly because your query is
> not closed. but thats just my guess.
>
> "Robert Emmons" <remmons@aurigen.com> wrote in message
> news:p3vh215nlk6okodmbd6fim3ckjron2te63@4ax.com...
>
>>I have a TADOQuery which I want to parametize by a field in one of 2
>>tables. I set it up like this:
>>
>>
>>Qry->Active = false;
>>Qry->Parameters->Clear();
>>Qry->SQL->Clear();
>>if(one){
>> Qry->SQL->Add("PARAMETERS Param1;");
>> Qry->SQL->Add("SELECT Field1, Field2, Field3");
>> Qry->SQL->Add("FROM Table");
>> Qry->SQL->Add("WHERE FLD1 = [Param1];");
>> Qry->Datasource = Table1Src;
>>}else{
>> Qry->SQL->Add("PARAMETERS Param2;");
>> Qry->SQL->Add("SELECT Field1, Field2, Field3");
>> Qry->SQL->Add("FROM Table");
>> Qry->SQL->Add("WHERE FLD1 = [Param2];");
>> Qry->Datasource = Table2Src;
>>}
>>Qry->Active = true;
>>
>>Table1 has one field: Param1.
>>Table2 has one field: Param2.
>>
>>The first time the query runs it works with either Table. However, if
>>the query is run a second time with the other Table, it fails.
>>
>>If the Table1 was used first, and then I switch to Table2, this is the
>>error message:
>>
>>Table2: Field not found Param1.
>>
>>It is as if the Query is still looking for Param1, although the SQL
>>TFields have been changed to use Param2, and the Datasource has been
>>changed to use Table2.
>>
>>I worked around this by adding dummy fields to Table1 (Param2), and
>>Table2 (Param1). Then everything works fine. However, it makes no
>>sense! Something is not being cleared out. The SQL strings have been
>>changed, but the query is still looking for the old parameter.
>>
>>Does anyone know what is wrong? What is not being reset soon enough?
>>
Thanks for the suggestion, but it did not work for me. I did try using
Qry->Close() even though Qry->Active = false is supposed to call Close().
I found a weird workaround although it makes no sense to me. Perhaps
someone else will understand it.
Each of the 2 parameter tables has a TADOTable component on the form. I
added a dummy TField to each table: param1 to table2 and param2 to
table1. Now there is no error message, and everything works fine.
I do not think the Query should really have anything to do with the
TADOTables. The query references the actual tables in the database, not
the TADOTables. The query should work even if the TADOTables do not exist.
Thanks again for any suggestions.
--
Robert Emmons
remmonsREMOVECAPS@aurigen.com
Technical Details
Message-ID:
<Rse7e.4887$g%3.2936@fe11.lga>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!hwmnpeer01.lga!hwmedia!hw-filter.lga!fe11.lga.POSTED!53ab2750!not-for-mailReferences:
<p3vh215nlk6okodmbd6fim3ckjron2te63@4ax.com> <42568656$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,3ff677fa598ef772 X-Google-Attributes: gid10698b,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!hwmnpeer01.lga!hwmedia!hw-filter.lga!fe11.lga.POSTED!53ab2750!not-for-mail From: Robert J Emmons <catch22@null.com> User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.database.ado Subject: Re: SQL Parameters not cleared References: <p3vh215nlk6okodmbd6fim3ckjron2te63@4ax.com> <42568656$1@newsgroups.borland.com> In-Reply-To: <42568656$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 72 Message-ID: <Rse7e.4887$g%3.2936@fe11.lga> Date: Wed, 13 Apr 2005 15:32:40 -0400 NNTP-Posting-Host: 68.193.2.59 X-Complaints-To: abuse@cv.net X-Trace: fe11.lga 1113420721 68.193.2.59 (Wed, 13 Apr 2005 12:32:01 MST) NNTP-Posting-Date: Wed, 13 Apr 2005 12:32:01 MST Organization: Optimum Online