Urgente

Delphi

01/11/2005

Estou aplicando uma query para o filtro do sorteio e após aplicar o sorteio de um registro preciso gravar os sorteados em outra tabela.

Está sorteando, mas na hora de gravar para a outra tabela está pegando um registro posterior ao sorteado, ou seja, se o registro sorteado é 8 está gravando o 9.

Alguém sabe como posso resolver o problema?

A rotina é a seguinte:

procedure TfrmSorteio.SpeedButton1Click(Sender: TObject);
var j,i,numsorteado:integer;
begin
qrSorteio.Close;
qrSorteio.SQL.Clear;
qrSorteio.SQL.Add(´ select nome, bairro, rg, telefone, celular, email, premio, promocao, data, hora from pesquisa´);
qrSorteio.SQL.Add(´where data between :datai and :dataf´);
qrSorteio.ParamByName(´datai´).AsDate:=dtmini.DateTime;
qrSorteio.ParamByName(´dataf´).AsDate:=dtmfim.DateTime;
qrSorteio.SQL.Add(´and hora between :horai and :horaf´);
qrSorteio.ParamByName(´horai´).Astime:=dtmhorai.DateTime;
qrSorteio.ParamByName(´horaf´).Astime:=dtmhoraf.DateTime;
qrSorteio.SQL.Add(´and premio=:premio´);
qrSorteio.ParamByName(´premio´).AsInteger:=dm.tbPremiosCODIGO.AsInteger;
qrSorteio.SQL.Add(´or premio is null´);
qrSorteio.Prepare;
qrSorteio.Open;
if qrSorteio.RecordCount > 0 then
begin
i:=qrSorteio.RecordCount;
qrSorteio.First;
Randomize;
for j := 1 to spcount.Value do
begin
numsorteado:=Random(i);
ShowMessage(´Numero sorteado: ´ + IntToStr(numsorteado));
qrSorteio.MoveBy(numsorteado);
dm.tbSorteio.Append;
dm.tbSorteioNOME.Value:=qrSorteio.fieldbyname(´nome´).AsString;
dm.tbSorteioBAIRRO.Value:=qrSorteio.fieldbyname(´bairro´).AsString;
dm.tbSorteioRG.Value:=qrSorteio.fieldbyname(´rg´).AsString;
dm.tbSorteioTELEFONE.Value:=qrSorteio.fieldbyname(´telefone´).AsString;
dm.tbSorteioCELULAR.Value:=qrSorteio.fieldbyname(´celular´).AsString;
dm.tbSorteioEMAIL.Value:=qrSorteio.fieldbyname(´email´).AsString;
dm.tbSorteioBAIRRO.Value:=qrSorteio.fieldbyname(´bairro´).AsString;
dm.tbSorteioPREMIO.Value:=dm.tbPremiosDESCRICAO.AsString;
dm.tbSorteioDATA.Value:=qrSorteio.fieldbyname(´data´).AsDateTime;
dm.tbSorteioHORA.Value:=qrSorteio.fieldbyname(´hora´).AsDateTime;
dm.tbSorteio.Post;
end;
end
else showmessage(´Não há dados para os parâmetros informados...´);
end;

[color=red:73677c42c0]Tópico bloqueado por Massuda [b:73677c42c0]Tópico duplicado[/b:73677c42c0] Por favor continuem a discussão no tópico original[/color:73677c42c0] http://forum.clubedelphi.net/viewtopic.php?t=70074



Sarnhold

Sarnhold

Curtidas 0
POSTAR