Re: Please help Dynamic ADO Query
- From: Opp <nospam@xxxxxxxxxxxxxxx>
- Date: Tue, 14 Jun 2005 13:13:44 +0100
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.
>
.
- Follow-Ups:
- Re: Please help Dynamic ADO Query
- From: Brian Bushay TeamB
- Re: Please help Dynamic ADO Query
- References:
- Please help Dynamic ADO Query
- From: Opp
- Please help Dynamic ADO Query
- Prev by Date: Re: Date Time formaat
- Next by Date: Re: Updates not applied when using cloned datasets
- Previous by thread: Re: Please help Dynamic ADO Query
- Next by thread: Re: Please help Dynamic ADO Query
- Index(es):
Relevant Pages
|