Re: Please help Dynamic ADO Query



Thanks for the relplies guys, found error was a dumb error on my part
(must have been a bit punchy when I first wrote initial test code)


Here is working version (helped by your guidelines ;))
===========================================
procedure TForm1.FormShow(Sender: TObject);

const ISQl = 'select * from Invoice Where InvNo =:ThisInv';
Const GSQL = 'select * from GlassInvItem where InvNo =:InvNo';
Const PSQL = 'select * from ProcInvItem where GlassInvItem =:ID';
const IASQl = 'select * from Invoice_archive Where InvNo =:ThisInv';
Const GASQL = 'select * from GlassInvItem_archive where InvNo
=:InvNo';
Const PASQL = 'select * from ProcInvItem_archive where GlassInvItem
=:ID';

var
x : Integer;
begin


With DataModule3 do
begin

//1. Set Sql depending on parameters passed to program
if ParamStr(1) = '1' then
begin
InvQry.sql.Add(ISQL);
GlassQry.SQL.Add(GSQL);
ProcQry.SQL.Add(PSQL);
InvQry.Connection := Con1;
GlassQry.Connection := Con1;
ProcQry.Connection := Con1;
end
else
begin
InvQry.sql.Add(IASQL);
GlassQry.SQL.Add(GASQL);
ProcQry.SQL.Add(PASQL);
InvQry.Connection := Con2;
GlassQry.Connection := Con2;
ProcQry.Connection := Con2;
end;
// Clear existing Params - if any
InvQry.Parameters.Clear;
GlassQry.Parameters.Clear;
ProcQry.Parameters.Clear;

// Setup master-detail stuff
GlassQry.DataSource := InvSrc;
ProcQry.DataSource := GlassSrc;

// add parameters
with InvQry.Parameters.AddParameter do begin
DataType := ftString;
Direction := pdInput;
Name := 'ThisInv';
Value := '';
end;
with GlassQry.Parameters.AddParameter do begin
DataType := ftString;
Direction := pdInput;
Name := 'InvNo';
Value := '';
end;
with ProcQry.Parameters.AddParameter do begin
DataType := ftString;
Direction := pdInput;
Name := 'ID';
Value := '';
end;

// Set parameter values - Hard-coded for test purposes
if ParamStr(1) = '1' then
InvQry.Parameters.ParamByName('ThisInv').Value := 'TR132262'
else
InvQry.Parameters.ParamByName('ThisInv').Value := 'TR141844';



InvQry.Prepared := true;
GlassQry.Prepared := true;
ProcQry.Prepared := true;

InvQry.Active := true;
GlassQry.Active := true;
ProcQry.Active := true;

end;

===========================================

It WOrks! Haleluyah... Program does seem slow to load for some reason
(pauses when loading, not sure if its an ADO-related issue - or my
coding.)


Anyway, thanks for you help.
Much appreciated..

Cheers..

Paul.

On Mon, 13 Jun 2005 12:41:32 +0100, Opp <nospam@xxxxxxxxxxxxxxx>
wrote:

>Hi -
>
>I have tried (fruitlessly) to dynamically interact with the
>TADOquery. In summary I would like to..
>
>1. Connect to a particular database (which will be defined via program
>parameters passed)
>2. Depending on which database we need to connect to, defined the
>appropriate SQl and set up necessary component properties so that we
>can define necessary master-detail settings.
>
>Here is an overview of the relationships involved..
>
>|--------------|
>|InvQry |
>|--------------|
>|
>|
>|---------------- |
>|GlassItem | Datasource set to InvQry Dataset
>|--------------- -|
>|
>|
>|----------------| Datasource set to GlassItem Dataset
>|ProcQry |
>|----------------|
>
>
>I can define and connect to the database statically, and all
>master-detail associations behave as designed / predicted.
>
>The problem is, when I try to define the necessary properties (sql and
>parameters) at run time - I get an error saying ...
>
>"Parameter object is improperly defined. Inconsistent or incomplete
>information was provided'. Process Project1.exe (3940)"
>
>Im pretty sure that all parameters are correct and have valid values -
>so I am stuck!
>
>
>Here is the code I am useing....
>
>===============================================
>
>const ISQl = 'select * from Invoice Where InvNo =:ThisInv';
>Const GSQL = 'select * from GlassInvItem where InvNo =:InvNo';
>Const PSQL = 'select * from ProcInvItem where GlassInvItem =:ID';
>const IASQl = 'select * from Invoice_archive Where InvNo =:ThisInv';
>Const GASQL = 'select * from GlassInvItem_archive where InvNo
>=:InvNo';
>Const PASQL = 'select * from ProcInvItem_archive where GlassInvItem
>=:ID';
>
>With DataModule3 do // Clear all previous SQL and parameter settings
> begin
> InvQry.sql.clear;
> GlassQry.SQL.Clear;
> ProcQry.SQL.Clear;
> InvQry.Parameters.Clear;
> GlassQry.Parameters.Clear;
> ProcQry.Parameters.Clear;
>
>
> if ParamStr(1) = '1' then // Dictates with tables - database to
>connect to
> begin
> InvQry.sql.Add(ISQL);
> GlassQry.SQL.Add(GSQL);
> ProcQry.SQL.Add(PSQL);
> InvQry.Parameters.ParamByName('ThisInv').Value := 'TR130639';
> InvQry.Connection := Con1;
> GlassQry.Connection := Con1;
> ProcQry.Connection := Con1;
> end
> else
> begin
> InvQry.sql.Add(IASQL);
> GlassQry.SQL.Add(GASQL);
> ProcQry.SQL.Add(PASQL);
> InvQry.Parameters.ParamByName('ThisInv').Value := 'TR141840';
> InvQry.Connection := Con2;
> GlassQry.Connection := Con2;
> ProcQry.Connection := Con2;
>
> end;
> with InvQry.Parameters.AddParameter do begin
> DataType := ftString;
> Direction := pdInput;
> Name := 'ThisInv';
> Value := '';
> end;
> with GlassQry.Parameters.AddParameter do begin
> DataType := ftString;
> Direction := pdInput;
> Name := 'InvNo';
> Value := '';
> end;
> with InvQry.Parameters.AddParameter do begin
> DataType := ftString;
> Direction := pdInput;
> Name := 'ID';
> Value := '';
> end;
>
>// Setup master-detail stuff
> GlassQry.DataSource := InvSrc;
> ProcQry.DataSource := GlassSrc;
> InvQry.Prepared := true;
> GlassQry.Prepared := true;
> ProcQry.Prepared := true;
>
>
> InvQry.Active := true;
> GlassQry.Active := true;
> ProcQry.Active := true;
>
> end;
>===============================================
>
>Any help anyone can give would be MUCH appreciated. I am using Delphi
>2005 (with service pack 3 intalled ;)) and trying to connect to an
>Access97 Database.
>
>Cheers..
>
>Paul.
>

.



Relevant Pages

  • a newby question
    ... I'm an ASP programmer for several month, and there's nothing I can't do ... results, news, database clients, etc, and it have a lot of SQL under SQL... ... in other words, I call the database and everytime I write a line, I ... table) but in the same page, without using the master-detail pages... ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: dbdebunk Quote of Week comment
    ... > a lot of really bad SQL programmers. ... But SQL does not have a pointer data type or the ... > being told to design a database. ... But why is little Cindy Lou Who employee ...
    (comp.databases.theory)
  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)
  • Re: dbdebunk Quote of Week comment
    ... > a lot of really bad SQL programmers. ... a surrogate key should support the primary key. ... But SQL does not have a pointer data type or the ... > being told to design a database. ...
    (comp.databases.theory)
  • Re: dbdebunk Quote of Week comment
    ... But SQL does not have a pointer data type or the ... More and more programmers who have absolutely no database training are ... But why is little Cindy Lou Who employee ...
    (comp.databases.theory)