Article View: borland.public.cppbuilder.database.ado
Article #765Re: SQL Parameters not cleared
From: James Peterson
Date: Fri, 08 Apr 2005 13:25
Date: Fri, 08 Apr 2005 13:25
50 lines
2866 bytes
2866 bytes
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?
>
Technical Details
Message-ID:
<42568656$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.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-mailReferences:
<p3vh215nlk6okodmbd6fim3ckjron2te63@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,3ff677fa598ef772 X-Google-Attributes: gid10698b,public X-Google-Language: ENGLISH,ASCII-7-bit From: "James Peterson" <jpeterson@romanmealmilling.com> Newsgroups: borland.public.cppbuilder.database.ado References: <p3vh215nlk6okodmbd6fim3ckjron2te63@4ax.com> Subject: Re: SQL Parameters not cleared Date: Fri, 8 Apr 2005 08:25:43 -0500 Lines: 52 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 64.21.236.129 Message-ID: <42568656$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1112966742 64.21.236.129 (8 Apr 2005 06:25:42 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.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