Board index » delphi » Linking parameters in SQL, Delphi and Databases

Linking parameters in SQL, Delphi and Databases

Hello,
Many apologies if I have the wrong forum - I am new to this.

I hope somebody will be able to help/advise me.  I am new to Delphi
Programming, Paradox Databases and SQL.  I have set up a Paradox
database and am using Delphi 3 as the GUI front end.  I have a
DBLookUpCombobox to select a year value from the paradox database.  I
want this value to be a parameter in a DBGrid - the content of which is
derived from SQL and invoked by a command button.

Although my program is compiling, a warning messages alerts me to the
fact that although a parameter is declared, it is not used.

The code for the command button is as follows: ...

procedure TFormOutstandingSubs.Button1Click(Sender: TObject);
var ParamByName : String;

begin
     with DataMenus.DataModule1.QuerySubs  do
          begin
          ParamByName('pyear').AsInteger:=
StrToInt(DBLookUpComboBox1.text);
          showmessage('value = ' + DBLookUpComboBox1.text);
          DataMenus.DataModule1.QuerySubs.ExecSQL;

          end;

     DBGridMembers.show;
     Button2.show;
     Label3.show;
end;

end.

The code for the SQL which is connected to the DBGrid  is as follows:

select

PaymentSubs.MembershipNo, Members.Title, Members.Firstname,
Members.Surname, PaymentSubs."Year", PaymentSubs.Paid

from

PaymentSubs, Members

where

PaymentSubs.MembershipNo = Members.MembershipNo and
PaymentSubs.Paid = False and
PaymentSubs."Year" = :pyear

...
It is compiling and when I set the SQL property to True is does show a
framework in the DBGrid.  I then reset it to false, run the program but
the DBGrid remains blank.  I get the message when compiling that the
pyear parameter is declared but never used.

I have spent hours trying to resolve this problem.  Can anyone help me
pls.

Many thanks

Debbie

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!

 

Re:Linking parameters in SQL, Delphi and Databases


I did not quite understand, if you have there Queries, QuerySubs and
then some other Query also.

If you have one query only, then for me it looks like you are not
trying to update any values in database with that query, but only
read the values. If this is the case, then you should not try to
use QuerySubs.ExecSQL.
Instead use QuerySubs.Close, set the query parameter values, and
then QuerySubs.Open.

I'm not sure if this will solve the problem, but maybe you can also
clarify your explanation.

Markku Nevalainen

Quote
Debbie wrote:

> The code for the command button is as follows: ...

> procedure TFormOutstandingSubs.Button1Click(Sender: TObject);
> var ParamByName : String;

> begin
>      with DataMenus.DataModule1.QuerySubs  do
>           begin
>           ParamByName('pyear').AsInteger:=
> StrToInt(DBLookUpComboBox1.text);
>           showmessage('value = ' + DBLookUpComboBox1.text);
>           DataMenus.DataModule1.QuerySubs.ExecSQL;

>           end;

>      DBGridMembers.show;
>      Button2.show;
>      Label3.show;
> end;

> end.

> The code for the SQL which is connected to the DBGrid  is as follows:

> select

> PaymentSubs.MembershipNo, Members.Title, Members.Firstname,
> Members.Surname, PaymentSubs."Year", PaymentSubs.Paid

> from

> PaymentSubs, Members

> where

> PaymentSubs.MembershipNo = Members.MembershipNo and
> PaymentSubs.Paid = False and
> PaymentSubs."Year" = :pyear

> ...
> It is compiling and when I set the SQL property to True is does show a
> framework in the DBGrid.  I then reset it to false, run the program but
> the DBGrid remains blank.  I get the message when compiling that the
> pyear parameter is declared but never used.

Re:Linking parameters in SQL, Delphi and Databases


Markku

Thank you so much for your suggestion -  it worked wonderfully.

However, I now have a further problem.  As you were able to gather from
my rather clumsy explanation, I am not updating any values in the
database just reading from it.  The DBLookUpComboBox now will read a
value from the database and this value will be passed as a parameter to
the SQL.  The SQL then retrieves further information (based on a query)
and puts it into the DBGrid.

As I said before you have solved my initial problem, however, if I then
want to change the option/value in the combo box by selecting from the
list of values,  when I click on the command button which generates the
actions above it only works once and even if I close the form, when I
return it is still there - I cannot not update it.  Do you have any
suggestions how to overcome this.

Many thanks once again for your help.

Debbie

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!

Re:Linking parameters in SQL, Delphi and Databases


Quote
Debbie wrote:

> actions above it only works once and even if I close the form, when I
> return it is still there - I cannot not update it.  Do you have any
> suggestions how to overcome this.

  Query.Close;
  Query.Open;
That's the basic way to make the query do a new select of data,
with new the SQL-sentence or parameters.

Re:Linking parameters in SQL, Delphi and Databases


Yep, brilliant - it works.

Thanks very much

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!

Other Threads