🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Usage of Parameters in ADOQuery

#996
From: Patrick Wong
Date: Sat, 27 Nov 2004 05:49
38 lines
2255 bytes
Dear all,

Are parameters only workable in "where" part of a ADOQuery's SQL statement?
I have the following code that does not work:

ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("select * from :TBL_NAME where id=':REC_ID'");
ADOQuery1->Parameters->ParamByName("TBL_NAME")->Value = EditTblName->Text;
ADOQuery1->Parameters->ParamByName("REC_ID")->Value = EditRecID->Text;
AnsiString chkStr1 = ADOQuery1->Parameters->ParamByName("TBL_NAME")->Value;
AnsiString chkStr2 = ADOQuery1->Parameters->ParamByName("REC_ID")->Value;
AnsiString chkStr3 = ADOQuery1->Parameters->ParseSQL(ADOQuery1->SQL->Text,
true);
ADOQuery1->Open();

chkStr1 and chkStr2 show both parameters are set properly, but chkStr3
always shows "select * from ? where id=':REC_ID'".  Exception of something
like "Parameters objects are not properly set..." is thrown when I attempt
to open the query.

The implementation as below works fine:

ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("select * from ");
ADOQuery1->SQL->Add(EditTblName->Text.c_str());
strcpy(_tmpStr, EditRecID->Text.c_str());
sprintf(&sqlstr[0], "where id=\'%s\'", _tmpStr);
ADOQuery1->SQL->Add(sqlstr);
AnsiString chkStr = ADOQuery1->SQL->Text;

chkStr shows correct concatenation for the SQL statement.

FYI, I am using BCB5 and MSSQL Server 2000.

Thanks for any advice,
Patrick
Technical Details
Message-ID: <41a81560$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,4778097d36f5a178,start
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Patrick Wong" <patrickwong@computer.org>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Usage of Parameters in ADOQuery
Date: Sat, 27 Nov 2004 13:49:21 +0800
Lines: 40
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 203.82.252.252
Message-ID: <41a81560$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101534560 203.82.252.252 (26 Nov 2004 21:49:20 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail