Fórum erro em agrupamento de sql #226803
19/04/2004
0
Tenho um list box que recebe informações de uma query,
só que não sei qual o erro quando tento agrupar informações
relativas ao item selecionado no listbox e tento jogar num
dbtext.
Se alguém puder ajudar agradeço.
*********FormShow
begin
ListBox1.Clear;
DM1.qTM.First;
while not DM1.qTM.Eof do
begin
ListBox1.Items.Add(DM1.qTM.FieldValues[´nome´]);
DM1.qTM.Next;
end;
end;
****************ListBox1Click
var
i,j: Integer;
sel:string;
begin
for i := 0 to (ListBox1.Items.Count - 1) do begin
if ListBox1.Selected[i] then
sel:=ListBox1.Items[i];
end;
with DM1.qAnT1 do
begin
DM1.qAnT1.Close;
DM1.qAnT1.SQL.Clear;
DM1.qAnT1.SQL.Add(´SELECT nome FROM estatistica´);
DM1.qAnT1.SQL.Add(´WHERE nome=:selec´);
DM1.qAnT1.SQL.Add(´AND e_digi=1 and e_digi=12 and e_digi=13 and e_digi=123´);
DM1.qAnT1.parameters.ParamByName(´selec´).Value:=sel;
DM1.qAnT1.open;
end;
j:=DM1.qAnT1.ExecSQL;
ShowMessage(inttostr(j));
dbt.Caption:=inttostr(j);
end;
N1
Curtir tópico
+ 0Posts
19/04/2004
Aroldo Zanela
e_digi não pode ter todos estes valores ao mesmo tempo, então, acho que o correto seria o operador [b:5ed250fd28]Or [/b:5ed250fd28]e não [b:5ed250fd28]And[/b:5ed250fd28].
Aqui usa-se RecordCount ao invés de ExecSQL para obter a quantidade de linhas no resultset.
Gostei + 0
19/04/2004
N1
Isto é, se eu retirar apenas o showmessage não mostra o valor
correto!!!???? :?:
Gostei + 0
19/04/2004
Vilaca
Não sei se é isso, mas tente inverter a ordem dos comandos
j:=DM1.qAnT1.ExecSQL;
dbt.Caption:=inttostr(j);
ShowMessage(inttostr(j));
Gostei + 0
19/04/2004
N1
Obrigado
Gostei + 0
19/04/2004
Aroldo Zanela
Não sei se é isso, mas tente inverter a ordem dos comandos
j:=DM1.qAnT1.ExecSQL;
dbt.Caption:=inttostr(j);
ShowMessage(inttostr(j));[/quote:64ee6862b9]
Tem certeza que usou ExecSQL ao invés de RecordCount?
Gostei + 0
19/04/2004
N1
o resultado estivesse correto, mas não estava.
O problema persiste tanto com execSQL quanto com o recordcount.
O showmessage enquanto ativo permite que
o valor real seja lido no dbtedit, tentei com um label simples mas
não funciona.
Gostei + 0
19/04/2004
Marco Salles
[b:e6f1d9f089]a)Voce Cita o [b]DbTetx[/b:e6f1d9f089][/b]
primeira Mensagem
sétima mensagem
Outrora Voce Cita Um BdEbitText
[b:e6f1d9f089]O DbText e Nem O DbEdit Tem a Propiedade Caption :?: :?: :?: [/b:e6f1d9f089]
Voce a Usa:
[b:e6f1d9f089]b)[/b:e6f1d9f089] se voce tiver usando o evento onclick do listBox voce pode substituir o Comando de varredura
for i := 0 to (ListBox1.Items.Count - 1) do begin if ListBox1.Selected[i] then sel:=ListBox1.Items[i]; end;
Por Uma única Instrução
sel:=ListBox1.Items.Strings[Listbox1.ItemIndex];
[b:e6f1d9f089]c)[/b:e6f1d9f089]
Voce esta usando um componente [b:e6f1d9f089]AdoQuery[/b:e6f1d9f089] :?: :?: ...Qual é o seu banco de dados :?: :?:A Consulta é muito simples para não funcionar :( :( :( ...Porque voce não usa um query :?: :?:
Se Não me enganos dois métodos Que voce usa são do componente TAdoQuery:
ADOQuery1.Parameters.ParamByName(´.....´).value:=sel; j:=ADOQuery1.ExecSQL;
Usando a Query Seria Um Pouco Diferente:
query1.ParamByName(´selec´).Value:=sel; j:=query1.RecordCount;//Conforme sugestão do Aroldo
Gostei + 0
19/04/2004
N1
Estou usando ACCESS , ADOTable.
DM1.qAnT1.Close;
DM1.qAnT1.SQL.Clear;
DM1.qAnT1.SQL.Add(´SELECT count(nome) FROM estatistica´);
DM1.qAnT1.SQL.Add(´WHERE nome=:selec´);
DM1.qAnT1.SQL.Add(´HAVING (e_digi=123 OR e_digi=12 OR e_digi=13 OR e_digi=1)´);
DM1.qAnT1.parameters.ParamByName(´selec´).Value:=sel;
i:=DM1.qAnT1.ExecSQL;
ShowMessage(inttostr(i));
DM1.qAnT1.open;
Percebi sobre o dbtedit, mesmo assim o valor ainda não está correto.
Gostei + 0
19/04/2004
Marco Salles
var i,j: Integer; sel:string; begin sel:=ListBox1.Items.Strings[Listbox1.ItemIndex]; DM1.qAnT1.Close; DM1.qAnT1.SQL.Clear; DM1.qAnT1.SQL.Add(´SELECT count(nome) as Quantidade FROM estatistica´); DM1.qAnT1.SQL.Add(´WHERE nome=:selec´); DM1.qAnT1.SQL.Add(´and (e_digi=123 OR e_digi=12 OR e_digi=13 OR e_digi=1)´); DM1.qAnT1.parameters.ParamByName(´selec´).Value:=sel; DM1.qAnT1.open; i:=DM1.qAnT1.FieldByName(´Quantidade´).asInteger; label1.Caption:=Inttostr(i); end;
[b:4da1614f4e]De Notícias...[/b:4da1614f4e]
Gostei + 0
19/04/2004
Marco Salles
var i,j: Integer; sel:string; begin sel:=ListBox1.Items.Strings[Listbox1.ItemIndex]; DM1.qAnT1.Close; DM1.qAnT1.SQL.Clear; DM1.qAnT1.SQL.Add(´SELECT count(nome) as Quantidade FROM estatistica´); DM1.qAnT1.SQL.Add(´WHERE nome=:selec´); DM1.qAnT1.SQL.Add(´and (e_digi=123 OR e_digi=12 OR e_digi=13 OR e_digi=1)´); DM1.qAnT1.parameters.ParamByName(´selec´).Value:=sel; DM1.qAnT1.open; i:=DM1.qAnT1.FieldByName(´Quantidade´).asInteger; label1.Caption:=Inttostr(i); end;
[b:4a74f95561]De Notícias...[/b:4a74f95561]
Gostei + 0
19/04/2004
Marco Salles
var i,j: Integer; sel:string; begin sel:=ListBox1.Items.Strings[Listbox1.ItemIndex]; DM1.qAnT1.Close; DM1.qAnT1.SQL.Clear; DM1.qAnT1.SQL.Add(´SELECT count(nome) as Quantidade FROM estatistica´); DM1.qAnT1.SQL.Add(´WHERE nome=:selec´); DM1.qAnT1.SQL.Add(´and (e_digi=123 OR e_digi=12 OR e_digi=13 OR e_digi=1)´); DM1.qAnT1.parameters.ParamByName(´selec´).Value:=sel; DM1.qAnT1.open; i:=DM1.qAnT1.FieldByName(´Quantidade´).asInteger; label1.Caption:=Inttostr(i); end;
[b:51a03dd812]De Notícias...[/b:51a03dd812]
Gostei + 0
19/04/2004
Marco Salles
var i,j: Integer; sel:string; begin sel:=ListBox1.Items.Strings[Listbox1.ItemIndex]; DM1.qAnT1.Close; DM1.qAnT1.SQL.Clear; DM1.qAnT1.SQL.Add(´SELECT count(nome) as Quantidade FROM estatistica´); DM1.qAnT1.SQL.Add(´WHERE nome=:selec´); DM1.qAnT1.SQL.Add(´and (e_digi=123 OR e_digi=12 OR e_digi=13 OR e_digi=1)´); DM1.qAnT1.parameters.ParamByName(´selec´).Value:=sel; DM1.qAnT1.open; i:=DM1.qAnT1.FieldByName(´Quantidade´).asInteger; label1.Caption:=Inttostr(i); end;
[b:09baa12809]De Notícias...[/b:09baa12809]
Gostei + 0
19/04/2004
Marco Salles
var i,j: Integer; sel:string; begin sel:=ListBox1.Items.Strings[Listbox1.ItemIndex]; DM1.qAnT1.Close; DM1.qAnT1.SQL.Clear; DM1.qAnT1.SQL.Add(´SELECT count(nome) as Quantidade FROM estatistica´); DM1.qAnT1.SQL.Add(´WHERE nome=:selec´); DM1.qAnT1.SQL.Add(´and (e_digi=123 OR e_digi=12 OR e_digi=13 OR e_digi=1)´); DM1.qAnT1.parameters.ParamByName(´selec´).Value:=sel; DM1.qAnT1.open; i:=DM1.qAnT1.FieldByName(´Quantidade´).asInteger; label1.Caption:=Inttostr(i); end;
[b:5f9e89c356]De Notícias...[/b:5f9e89c356]
Gostei + 0
19/04/2004
N1
Fiz mais testes e realmente funcionou.
Obrigado
:D
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)