 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
James Guest
|
Posted: Thu May 20, 2004 3:29 pm Post subject: Datamodules and TQuery |
|
|
I am having a hard time organizing my project to use Datamodules. I have
done it in the past when working with TTable but since I am now working with
SQL I find it very difficult. Almost each query I have even to the same
table is different. Sometimes I only need 1 field returned some times more.
I only have 1 datamode with the sql server connection components in it. My
project is filled with individual query components on each form and I do not
like that. Any suggestion on how I can use Datamodules and eliminate the
need to have all these tquery components on each form.
Thanks
Jame
|
|
| Back to top |
|
 |
Jeremy Collins Guest
|
Posted: Thu May 20, 2004 3:32 pm Post subject: Re: Datamodules and TQuery |
|
|
James wrote:
| Quote: | I am having a hard time organizing my project to use Datamodules. I have
done it in the past when working with TTable but since I am now working with
SQL I find it very difficult. Almost each query I have even to the same
table is different. Sometimes I only need 1 field returned some times more.
I only have 1 datamode with the sql server connection components in it. My
project is filled with individual query components on each form and I do not
like that. Any suggestion on how I can use Datamodules and eliminate the
need to have all these tquery components on each form.
|
1. Populate the SQL from code
2. Create stored procedures in your database, and execute those
via an ADOCommand.
I prefer 2, as it keeps the database logic nicely separated,
and other applications can use the stored procedures if
required.
--
jc
Remove the -not from email
|
|
| Back to top |
|
 |
Kevin Frevert Guest
|
Posted: Thu May 20, 2004 4:00 pm Post subject: Re: Datamodules and TQuery |
|
|
James,
http://community.borland.com/article/0,1410,20563,00.html
Good luck,
krf
"James" <sundiskAThotpop.com> wrote
| Quote: | I am having a hard time organizing my project to use Datamodules. I have
done it in the past when working with TTable but since I am now working
with
SQL I find it very difficult. Almost each query I have even to the same
table is different. Sometimes I only need 1 field returned some times
more.
I only have 1 datamode with the sql server connection components in it.
My
project is filled with individual query components on each form and I do
not
like that. Any suggestion on how I can use Datamodules and eliminate the
need to have all these tquery components on each form.
Thanks
Jame
|
|
|
| Back to top |
|
 |
Michael Luna Guest
|
Posted: Thu May 20, 2004 5:40 pm Post subject: Re: Datamodules and TQuery |
|
|
I Create most of queries in Code
var
q : TADOQuery;
begin
q := TADOQuery.Create(self) ;
q.ConnectionString := 'Provider=MSDASQL.1;Persist Security Info=False;'
+ 'Data Source=dBASE Files;Initial '
+ 'Catalog=' + GetTablePath() ;
or
var
q : TADOQuery;
begin
q := TADOQuery.Create(self) ;
q.Connection := DMVoterData.ADOConLAX;
WHERE DMVoterData.ADOConLAX is an ADO connection in a DataMondule.
I also have one or two TADO querys on the form for population of data
controls or globla referanced results.
"James" <sundiskAThotpop.com> wrote
| Quote: | I am having a hard time organizing my project to use Datamodules. I have
done it in the past when working with TTable but since I am now working
with
SQL I find it very difficult. Almost each query I have even to the same
table is different. Sometimes I only need 1 field returned some times
more.
I only have 1 datamode with the sql server connection components in it.
My
project is filled with individual query components on each form and I do
not
like that. Any suggestion on how I can use Datamodules and eliminate the
need to have all these tquery components on each form.
Thanks
Jame
|
|
|
| Back to top |
|
 |
Jon Purvis Guest
|
Posted: Thu May 20, 2004 7:25 pm Post subject: Re: Datamodules and TQuery |
|
|
James wrote:
| Quote: | I am having a hard time organizing my project to use Datamodules. I have
done it in the past when working with TTable but since I am now working with
SQL I find it very difficult. Almost each query I have even to the same
table is different. Sometimes I only need 1 field returned some times more.
I only have 1 datamode with the sql server connection components in it. My
project is filled with individual query components on each form and I do not
like that. Any suggestion on how I can use Datamodules and eliminate the
need to have all these tquery components on each form.
Thanks
Jame
|
I create all queries in code. I'm considering moving some to stored procedures for my current
project, but don't see a big need to do this. Most of my projects have 1 query object for the
entire application, and I create the SQL string each time I need it. In the current project I have
4 query objects, but only because several are needed to be used at the same time in specific instances.
Typical queries for me are shown below. When they are more complicated, I create the query string
in multiple parts using if/then and case statements. May or may not be the best way, but for my
small databases with 3-5 users, it works fine.
procedure TForm1.DoSomething;
begin
with DataModule1 do begin
qryTemp.Close;
qryTemp.SQL.Clear;
qryTemp.SQL.Add('select count(PermitSeq) as FacilityCount from Permits where FacilityID='
+IntToStr(tblPermits['FacilityID']));
qryTemp.Open;
{ do something with data }
qryTemp.Close;
qryTemp.SQL.Clear;
qryTemp.SQL.Add('select Customers.CustomerID,NameLNF,Permits.PermitSeq,'
+'Organization,Permits.PermitID from Customers,Permits,CustomerPermits, '
+'Organizations where Customers.CustomerID=CustomerPermits.CustomerID and '
+'Permits.PermitSeq=CustomerPermits.PermitSeq and Permits.OrganizationSeq'
+'*=Organizations.OrganizationSeq');
qryTemp.SQL.Add(PermitString);
case rgSearch.ItemIndex of
0: qryTemp.SQL.Add('and NameLNF like '''+EditSearch.Text+'%'' order by NameLNF,'
+'Organization,Permits.PermitID');
1: qryTemp.SQL.Add('and Organization like '''+EditSearch.Text+'%'' order by '
+'Organization,NameLNF,Permits.PermitID');
2: qryTemp.SQL.Add('and Permits.PermitID like '''+EditSearch.Text+'%'' order '
+'by Permits.PermitID,NameLNF,Organization');
end;
qryTemp.Open;
{ do something with data }
end;
end;
|
|
| Back to top |
|
 |
|
|
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
|
|