BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TADOQuery - using 2 detail parameters for same master field

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Jon Scott
Guest





PostPosted: Sat Feb 28, 2004 7:35 pm    Post subject: TADOQuery - using 2 detail parameters for same master field Reply with quote



I use TADOQuery on an Access database and have a master/detail relationship between two tables.
On the detail table SQL, I have something like:

SELECT * FROM Detail
WHERE ((Detail.Field1 LIKE '%' + :PARENTFIELD + '%')
OR (Detail.Field2 = :PARENTFIELD))

However, I notice that TADOQuery only fills in the first parameter and ignores the second one
(it is null). The only way I can get this to work is to manually fill in the parameters
whenever a user moves between records on the master table and Requery the detail table. Is
there a way to make this work using TADOQuery or another ADO descendant component (freeware)?
Does using TADODataSet or TADOTable make any difference? I have yet to try those.

--

Thanks,
Jon E. Scott
Blue Orb Software
http://www.blueorbsoft.com



Back to top
Jon Scott
Guest





PostPosted: Sat Feb 28, 2004 7:39 pm    Post subject: Re: TADOQuery - using 2 detail parameters for same master fi Reply with quote



And if it makes any difference, I'm using D5 Ent.

--

Thanks,
Jon E. Scott
Blue Orb Software
http://www.blueorbsoft.com


"Jon Scott" <NOSPAMsupport (AT) blueorbsoft (DOT) comNOSPAM> wrote

Quote:
I use TADOQuery on an Access database and have a master/detail relationship between two
tables.
On the detail table SQL, I have something like:

SELECT * FROM Detail
WHERE ((Detail.Field1 LIKE '%' + :PARENTFIELD + '%')
OR (Detail.Field2 = :PARENTFIELD))

However, I notice that TADOQuery only fills in the first parameter and ignores the second one
(it is null). The only way I can get this to work is to manually fill in the parameters
whenever a user moves between records on the master table and Requery the detail table. Is
there a way to make this work using TADOQuery or another ADO descendant component (freeware)?
Does using TADODataSet or TADOTable make any difference? I have yet to try those.

--

Thanks,
Jon E. Scott
Blue Orb Software
http://www.blueorbsoft.com






Back to top
Jon Scott
Guest





PostPosted: Sun Feb 29, 2004 3:19 am    Post subject: Re: TADOQuery - using 2 detail parameters for same master fi Reply with quote



Of course, you can name a parameter whatever you want, but for TADOQuery, it must be the master
table's fieldname. How else would it know what field to get the value from? Try it out and
you'll see what I mean.

--

Thanks,
Jon E. Scott
Blue Orb Software
http://www.blueorbsoft.com


"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote

Quote:
I use TADOQuery on an Access database and have a master/detail relationship between two
tables.
On the detail table SQL, I have something like:

SELECT * FROM Detail
WHERE ((Detail.Field1 LIKE '%' + :PARENTFIELD + '%')
OR (Detail.Field2 = :PARENTFIELD))

However, I notice that TADOQuery only fills in the first parameter and ignores the second one
(it is null). The only way I can get this to work is to manually fill in the parameters
whenever a user moves between records on the master table and Requery the detail table. Is
there a way to make this work using TADOQuery or another ADO descendant component (freeware)?
Does using TADODataSet or TADOTable make any difference? I have yet to try those.

--

ADO doesn't support parameters of the same name in a query. Rename your second
parameter and your query will work.
--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]



Back to top
Jon Scott
Guest





PostPosted: Sun Feb 29, 2004 5:57 pm    Post subject: Re: TADOQuery - using 2 detail parameters for same master fi Reply with quote

Yes, that's exactly what I'm doing, but thought there was a way I didn't have to do it manually.
Thanks anyway.

--
Jon E. Scott
Blue Orb Software
http://www.blueorbsoft.com


"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote

Quote:

Of course, you can name a parameter whatever you want, but for TADOQuery, it must be the
master
table's fieldname. How else would it know what field to get the value from? Try it out and
you'll see what I mean.

The SQL passed to ADO can't have parameters of the same name.
Borlands ADO components are not going to maintain master/Detail with your SQL.
You will need to change the name of one of the parameters then write code for
the master tables AfterScroll event to handle setting the detail table
parameters and then REQUERY

--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]



Back to top
Vitali Kalinin
Guest





PostPosted: Mon Mar 01, 2004 9:38 am    Post subject: Re: TADOQuery - using 2 detail parameters for same master fi Reply with quote

In this specific case you can adjust yours SQL like this:
SELECT * FROM Detail
WHERE ((Detail.Field1 LIKE '%' + Detail.Field2 + '%')
OR (Detail.Field2 = :PARENTFIELD))

"Jon Scott" <NOSPAMsupport (AT) blueorbsoft (DOT) comNOSPAM> сообщил/сообщила в
новостях следующее: news:4042280c$1 (AT) newsgroups (DOT) borland.com...
Quote:
Yes, that's exactly what I'm doing, but thought there was a way I didn't
have to do it manually.
Thanks anyway.

--
Jon E. Scott
Blue Orb Software
http://www.blueorbsoft.com


"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:390440h4q1lk3a80j93klbituttrdci29d (AT) 4ax (DOT) com...

Of course, you can name a parameter whatever you want, but for
TADOQuery, it must be the
master
table's fieldname. How else would it know what field to get the value
from? Try it out and
you'll see what I mean.

The SQL passed to ADO can't have parameters of the same name.
Borlands ADO components are not going to maintain master/Detail with
your SQL.
You will need to change the name of one of the parameters then write
code for
the master tables AfterScroll event to handle setting the detail table
parameters and then REQUERY

--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]





Back to top
Vitali Kalinin
Guest





PostPosted: Mon Mar 01, 2004 10:55 am    Post subject: Re: TADOQuery - using 2 detail parameters for same master fi Reply with quote

Sorry this won't work
"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> сообщил/сообщила в новостях
следующее: news:40430525 (AT) newsgroups (DOT) borland.com...
Quote:
In this specific case you can adjust yours SQL like this:
SELECT * FROM Detail
WHERE ((Detail.Field1 LIKE '%' + Detail.Field2 + '%')
OR (Detail.Field2 = :PARENTFIELD))

"Jon Scott" <NOSPAMsupport (AT) blueorbsoft (DOT) comNOSPAM> сообщил/сообщила в
новостях следующее: news:4042280c$1 (AT) newsgroups (DOT) borland.com...
Yes, that's exactly what I'm doing, but thought there was a way I didn't
have to do it manually.
Thanks anyway.

--
Jon E. Scott
Blue Orb Software
http://www.blueorbsoft.com


"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:390440h4q1lk3a80j93klbituttrdci29d (AT) 4ax (DOT) com...

Of course, you can name a parameter whatever you want, but for
TADOQuery, it must be the
master
table's fieldname. How else would it know what field to get the
value
from? Try it out and
you'll see what I mean.

The SQL passed to ADO can't have parameters of the same name.
Borlands ADO components are not going to maintain master/Detail with
your SQL.
You will need to change the name of one of the parameters then write
code for
the master tables AfterScroll event to handle setting the detail table
parameters and then REQUERY

--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]







Back to top
Mike Walsh
Guest





PostPosted: Wed Mar 03, 2004 1:56 pm    Post subject: Re: TADOQuery - using 2 detail parameters for same master fi Reply with quote


"Jon Scott" <NOSPAMsupport (AT) blueorbsoft (DOT) comNOSPAM> wrote

Quote:
Yes, that's exactly what I'm doing, but thought there was a way I didn't
have to do it manually.
Thanks anyway.

Jon,


Several times to other posters, I've mentioned in these groups a method that
I use, and noone has ever commented on it. So, I don't know if there's any
reason not to use it, but I do and it works (at least against Microsoft SQL
Server). What I do is include a variable in my script, then set the var =
parameter, then my where clause uses the var instead. For example your query
would be

declare
@ParentField varchar (200) -- or whatever it is

set @ParentField = :ParentField

SELECT * FROM Detail
WHERE ((Detail.Field1 LIKE '%' + @ParentField + '%')
OR (Detail.Field2 = :@ParentField))

If any gurus out there see a problem with this approach, I'd love to hear
about it.

Mike Walsh



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.