Article View: borland.public.cppbuilder.database.ado
Article #1020Usage of Parameters in ADOQuery
From: Patrick Wong
Date: Thu, 09 Dec 2004 06:16
Date: Thu, 09 Dec 2004 06:16
38 lines
2257 bytes
2257 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:
<41b7edc8@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!transit.nntp.hccnet.nl!newsfeed.wirehub.nl!194.72.7.126.MISMATCH!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10698b,511e64aaadff0c66,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: Thu, 9 Dec 2004 14:16:41 +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: <41b7edc8@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1102573000 203.82.252.252 (8 Dec 2004 22:16:40 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!transit.nntp.hccnet.nl!newsfeed.wirehub.nl!194.72.7.126.MISMATCH!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail