Board index » delphi » Database Problem-----Why won't this work?

Database Problem-----Why won't this work?

Help me please.  Why won't this bit of code work?  I keep getting
error messages with it and cannot, for the life of me, work it out.

Any help would be most appreciated.

procedure newrankings(Sender: TObject);
var rankingcount:integer;
begin
{clear rankings from fighter table}
datamodule1.Fightertable.first;
repeat
datamodule1.Fightertable.edit;
datamodule1.Fightertable.FieldByName('Ranking').AsInteger:=0;
datamodule1.Fightertable.post;
datamodule1.Fightertable.next;
until datamodule1.Fightertable.eof=true;

{heavyweight rankings}
DataModule1.Fighterquery.Close;
DataModule1.Fighterquery.prepare;
DataModule1.Fighterquery.SQL.clear;
DataModule1.Fighterquery.SQL.Add('Select * from fighters99');
DataModule1.Fighterquery.SQL.Add('where PresentDivision=''H''');
DataModule1.Fighterquery.SQL.Add('Order by PerformancePoints Desc');
DataModule1.Fighterquery.Open;
Datamodule1.fighterquery.first;
rankingcount:=0;
repeat
rankingcount:=rankingcount+1;
until rankingcount=1;
end;

 

Re:Database Problem-----Why won't this work?


What kind of error messages do you get?

--
Andreas Klein
eMail: a-k...@metronet.de

box...@clara.net schrieb in Nachricht <356aa476.13089...@news.clara.net>...

Quote
>Help me please.  Why won't this bit of code work?  I keep getting
>error messages with it and cannot, for the life of me, work it out.

>Any help would be most appreciated.

>procedure newrankings(Sender: TObject);
>var rankingcount:integer;
>begin
>{clear rankings from fighter table}
>datamodule1.Fightertable.first;
>repeat
>datamodule1.Fightertable.edit;
>datamodule1.Fightertable.FieldByName('Ranking').AsInteger:=0;
>datamodule1.Fightertable.post;
>datamodule1.Fightertable.next;
>until datamodule1.Fightertable.eof=true;

>{heavyweight rankings}
>DataModule1.Fighterquery.Close;
>DataModule1.Fighterquery.prepare;
>DataModule1.Fighterquery.SQL.clear;
>DataModule1.Fighterquery.SQL.Add('Select * from fighters99');
>DataModule1.Fighterquery.SQL.Add('where PresentDivision=''H''');
>DataModule1.Fighterquery.SQL.Add('Order by PerformancePoints Desc');
>DataModule1.Fighterquery.Open;
>Datamodule1.fighterquery.first;
>rankingcount:=0;
>repeat
>rankingcount:=rankingcount+1;
>until rankingcount=1;
>end;

Re:Database Problem-----Why won't this work?


procedure

Quote
box...@clara.net wrote in message <356aa476.13089...@news.clara.net>...
>Help me please.  Why won't this bit of code work?  I keep getting
>error messages with it and cannot, for the life of me, work it out.

>Any help would be most appreciated.

>procedure newrankings(Sender: TObject);

procedure WhatClassIsIt.newrankings(Sender: TObject);

{ That is datamodule1 a global object? }

Quote
>var rankingcount:integer;
>begin
>{clear rankings from fighter table}
>datamodule1.Fightertable.first;
>repeat
>datamodule1.Fightertable.edit;
>datamodule1.Fightertable.FieldByName('Ranking').AsInteger:=0;
>datamodule1.Fightertable.post;
>datamodule1.Fightertable.next;
>until datamodule1.Fightertable.eof=true;

>{heavyweight rankings}
>DataModule1.Fighterquery.Close;
>DataModule1.Fighterquery.prepare;
>DataModule1.Fighterquery.SQL.clear;
>DataModule1.Fighterquery.SQL.Add('Select * from fighters99');
>DataModule1.Fighterquery.SQL.Add('where PresentDivision=''H''');
>DataModule1.Fighterquery.SQL.Add('Order by PerformancePoints Desc');
>DataModule1.Fighterquery.Open;
>Datamodule1.fighterquery.first;
>rankingcount:=0;
>repeat
>rankingcount:=rankingcount+1;
>until rankingcount=1;
>end;

Instead of using tables as I suppose you use use TQuery and ExecSQL some
thing like:

procedure MyClass.resetFighterTableValueRanking;
var
    Q: TQuery;
begin
    try
        Q:= TQuery.create(self);
        try
            Q.DatabaseName := <ansAlias>;
            Q.SQL.Add( 'update FigtherTable set Ranking = 0;' );
//  ore            Q.SQL.Add( 'update FigtherTable set Ranking = 0 where
ranking>50;' );
            Q.ExecSQL;
        except
            on E: Exception  do begin
                MessageDlg( E.Message, mtInformation, [mbOK], 0 );
            end;
        end;
    finally
        Q.Free;
    end;
end;

end;

Re:Database Problem-----Why won't this work?


Try getting rid of the Prepare.  The Prepare (as I understood) was to bind
parameter values to a query already parsed and prepared for submission.
Since your creating the SQL text after prepare, that doesn't seem to make
sense.  Also, depending whether your using SQL Links or ODBC, prepare may
cause problems.

Other Threads