🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Flexible SQL Queries through ADO.

#1619
From: Mark Guerrieri
Date: Wed, 02 Jun 2004 18:30
96 lines
4052 bytes
Ah yes, I missed that- the column and table names can not be parameters- you
need to dynamically add them to your SQL string.

Mark

"Viatcheslav V. Vassiliev" <support@oledbdirect.com> wrote in message
news:40bd7880@newsgroups.borland.com...
> SELECT ?, ?
>
> Most (if not all) DBMS will not allow parameters at this place. Enclose
also
> column names into quotes - Date is probably keyword. Use TADODataSet and
set
> CommandText property.
>
> //------------------------------------------
> Regards,
> Vassiliev V. V.
> http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
> ADO.Net
> http://www.oledbdirect.com - The fastest way to access MS SQL Server,
> MS Jet (Access) and Interbase (through OLEDB)
>
> "Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.no_spam.c0m.no_spam>
> �������/�������� � �������� ���������:
> news:40bb4d03$1@newsgroups.borland.com...
> >
> > Thanks Mark,
> >
> > The first method works fine for me.
> >
> > Although I did try your second method, and it didn't seem to work.
> > Is there something special that changes in the SQL Query?
> >
> > i.e.
> > C++ Code
> > DynamicFlexSQLStmt = "SELECT :Var1, :Var2 ";
> > DynamicFlexSQLStmt += "FROM mySQLTable ";
> > DynamicFlexSQLStmt += "WHERE Date >= :StartDate ";
> > DynamicFlexSQLStmt += "AND Date <= :EndDate ";
> >
> > TADOQuery1->Parameters->ParseSQL(DynamicFlexSQLStmt, true);
> > TADOQuery1->Parameters->ParamByName("Var1")->Value = "Date";
> > etc...
> >
> > Debugging the DynamicFlexSQLStmt
> > DynamicFlexSQLStmt = "SELECT ?, ? FROM mySQLTable WHERE Date >= ? AND
Date
> <= ?"
> > It starts when the ParseSQL statement command is executed,
> > and remains that way after all the ParamByName statements are called
> >
> > I get an error "No Value given for one or more required Parameters"
> >
> > Any thoughts?
> > And THANKS A LOT for the your reply!
> > You've helped a whole heaps load!
> >
> > Heinz.
> >
> >
> >
> > "Mark Guerrieri" <markg11@comcast.net> wrote:
> > >>
> > >> AnsiString DynamicFlexSQLStmt = "SELECT Date " + ""... (Whatever I
add
> for
> > >Column Selections)
> > >>
> > >> I cannont use TADOQuery1->SQL->Add(":MyFlexibleSQLStmt");
> > >> TADOQuery1->SQL->Parameters->ParamByName("MyFlexibleSQLStmt")->Value
=
> > >DynamicFlexSQLStmt;
> > >>
> > >
> > >Try this-
> > >
> > >AnsiString DynamicFlexSQLStmt = "SELECT Date " + ""... (Whatever I add
> for
> > >Column Selections)
> > >TADOQuery1->SQL->Text = DynamicFlexSQLStmt;
> > >
> > >I do this all the time and it works fine.  I don't bother with
> parameters,
> > >I just build the values right into the SQL statement.  If you need
> > >parameters, add this:
> > >
> > >TADOQuery1->Parameters->ParseSQL(DynamicFlexSQLStmt, true);
> > >TADOQuery1->Parameters->ParamByName("ParamName")->Value = ParamValue;
> > >
> > >Mark
> > >
> > >
> >
>
>
Technical Details
Message-ID: <40be1ca0$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40ba50b3$1@newsgroups.borland.com> <40baa32b$1@newsgroups.borland.com> <40bb4d03$1@newsgroups.borland.com> <40bd7880@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10698b,88aab88ffc95b09
X-Google-Attributes: gid10698b,public
Reply-To: "Mark Guerrieri" <mguerrieri@cmsgrp.com>
From: "Mark Guerrieri" <mguerrieri@cmsgrp.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <40ba50b3$1@newsgroups.borland.com> <40baa32b$1@newsgroups.borland.com> <40bb4d03$1@newsgroups.borland.com> <40bd7880@newsgroups.borland.com>
Subject: Re: Flexible SQL Queries through ADO.
Date: Wed, 2 Jun 2004 14:30:04 -0400
Lines: 98
Organization: Creative Marketing Strategies
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 66.200.143.50
Message-ID: <40be1ca0$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1086200992 66.200.143.50 (2 Jun 2004 11:29:52 -0700)
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail