Article View: borland.public.cppbuilder.database.ado
Article #916SQL Parameters not cleared
From: Robert Emmons
Date: Sat, 05 Mar 2005 00:25
Date: Sat, 05 Mar 2005 00:25
43 lines
2426 bytes
2426 bytes
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:
<p3vh215nlk6okodmbd6fim3ckjron2te63@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10698b,3ff677fa598ef772,start X-Google-Attributes: gid10698b,public X-Google-Language: ENGLISH,ASCII-7-bit From: Robert Emmons <remmons@aurigen.com> Newsgroups: borland.public.cppbuilder.database.ado Subject: SQL Parameters not cleared Date: Fri, 04 Mar 2005 19:25:31 -0500 Message-ID: <p3vh215nlk6okodmbd6fim3ckjron2te63@4ax.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 68.193.14.50 X-Trace: newsgroups.borland.com 1109982217 68.193.14.50 (4 Mar 2005 16:23:37 -0800) Lines: 44 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail