Registro não encontrado!

10/08/2004

0

Pessoal, como faço para q numa consulta, ao não achar o nome da pessoa vir showmessage, registro não encontrado! meu código do botão está assim:

ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(´SELECT Nome, Telefone FROM tb_profe´);
ADOQuery1.SQL.Add(´WHERE Nome=´+´´´´+Edit1.Text+´´´´); /// olha aqui a alteração
ADOQuery1.Open;


tinha feito algo como:
if ADOQuery1.EOF then
blabla

mas não sei se está coerente isso, alguem pode me dar uma luz?

obrigado.


Rockbilly

Rockbilly

Responder

Posts

10/08/2004

Melo

Faz o Seguinte quando vc der o ´Open´ na tabela , verifica se ele estar vazio. caso de afirmativo de um showmessage.

ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(´SELECT Nome, Telefone FROM tb_profe´);
ADOQuery1.SQL.Add(´WHERE Nome=´+´´´´+Edit1.Text+´´´´); /// olha aqui a alteração
ADOQuery1.Open;

// a Verificação se a Query esta vazia ou não
if ADOQuery1.isEmpty then
Showmessage(´A pesquisa não retornou nenhum Resultado´)

Espero Ter Ajudado
Melo


Responder

11/08/2004

Rockbilly

brigado melo, vou tentar fazer isso!


Responder

13/08/2004

Rockbilly

não deu certo, ele sempre dá ´Registro não encotrado!´, olhem meu código:
if not (ADOQuery1.IsEmpty) Then
  begin
   ADOQuery1.SQL.Add(´SELECT Nome As NOMES, Telefone As FONE FROM tb_profe´);
   ADOQuery1.SQL.Add(´WHERE Nome=´+´´´´+Edit1.Text+´´´´);
   ADOQuery1.Open;
   ADOQuery1.Close;
   ADOQuery1.SQL.Clear;

  end
 else
  begin
   ShowMessage(´Registro não encontrado!´);
  end;
end;



e tb:
if not (ADOQuery1.EOF) Then
  begin
   ADOQuery1.SQL.Add(´SELECT Nome As NOMES, Telefone As FONE FROM tb_profe´);
   ADOQuery1.SQL.Add(´WHERE Nome=´+´´´´+Edit1.Text+´´´´);
   ADOQuery1.Open;
   ADOQuery1.Close;
   ADOQuery1.SQL.Clear;

  end
 else
  begin
   ShowMessage(´Registro não encontrado!´);
  end;
end;



Responder

13/08/2004

Rockbilly

desculpa, os códigos são esses:
if not (ADOQuery1.IsEmpty) Then 
  begin 
ADOQuery1.Close; 
   ADOQuery1.SQL.Clear; 
   ADOQuery1.SQL.Add(´SELECT Nome As NOMES, Telefone As FONE FROM tb_profe´); 
   ADOQuery1.SQL.Add(´WHERE Nome=´+´´´´+Edit1.Text+´´´´); 
   ADOQuery1.Open; 
     end 
else 
  begin 
   ShowMessage(´Registro não encontrado!´); 
  end; 
end; 




e tb:
if not (ADOQuery1.EOF) Then 
  begin 
ADOQuery1.Close; 
   ADOQuery1.SQL.Clear; 
ADOQuery1.SQL.Add(´SELECT Nome As NOMES, Telefone As FONE FROM tb_profe´); 
   ADOQuery1.SQL.Add(´WHERE Nome=´+´´´´+Edit1.Text+´´´´); 
   ADOQuery1.Open; 
   
  end 
else 
  begin 
   ShowMessage(´Registro não encontrado!´); 
  end; 
end; 



Responder

13/08/2004

Macario

desculpa, os códigos são esses:
if not (ADOQuery1.IsEmpty) Then 
  begin 
ADOQuery1.Close; 
   ADOQuery1.SQL.Clear; 
   ADOQuery1.SQL.Add(´SELECT Nome As NOMES, Telefone As FONE FROM tb_profe´); 
   ADOQuery1.SQL.Add(´WHERE Nome=´+´´´´+Edit1.Text+´´´´); 
   ADOQuery1.Open; 
     end 
else 
  begin 
   ShowMessage(´Registro não encontrado!´); 
  end; 
end; 
e tb:
if not (ADOQuery1.EOF) Then 
  begin 
ADOQuery1.Close; 
   ADOQuery1.SQL.Clear; 
ADOQuery1.SQL.Add(´SELECT Nome As NOMES, Telefone As FONE FROM tb_profe´); 
   ADOQuery1.SQL.Add(´WHERE Nome=´+´´´´+Edit1.Text+´´´´); 
   ADOQuery1.Open; 
   
  end 
else 
  begin 
   ShowMessage(´Registro não encontrado!´); 
  end; 
end; 


Olá programador, boa tarde.

Primeiro voce executa a Query, e depois verifica o estado da mesma.

[color=red:3bcde6d36f] ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add(´SELECT Nome As NOMES, Telefone As FONE FROM tb_profe´); ADOQuery1.SQL.Add(´WHERE Nome=´+´´´´+Edit1.Text+´´´´); ADOQuery1.Open; if ADOQuery1.isEmpty then ShowMessage(´Não há dados a exibir´);[/color:3bcde6d36f]



Responder

13/08/2004

Rockbilly

Oi gente fina, vou testa isso e qq coisa posto... vlw a atenção!


Responder

13/08/2004

Macario

Há uma dica pro seu código.

Tente assim:

[color=green:43e4c9dac0]
with ADOQuery1 do
  begin
    Close; 
    SQL.Clear; 
    SQL.Add(´SELECT Nome As NOMES, Telefone As FONE FROM tb_profe´); 
    SQL.Add(´WHERE Nome=´+QuotedStr(Edit1.Text); 
    Open; 
  end;

if ADOQuery1.isEmpty then 
ShowMessage(´Não há dados a exibir´);
[/color:43e4c9dac0]


ou assim:
[color=green:43e4c9dac0]
with ADOQuery1 do
  begin
    Close; 
    SQL.Clear; 
    SQL.Add(´SELECT Nome As NOMES, Telefone As FONE FROM tb_profe´); 
    SQL.Add(´WHERE Nome= :Codigo´); 
[color=red]    Params.ParamByName(´Codigo´).asString := edit1.text;[/color]
    Open; 
  end;

if ADOQuery1.isEmpty then 
ShowMessage(´Não há dados a exibir´);
[/color:43e4c9dac0]


na linha em vermelho voce usa atribui o parametro conforme o tipo do dado: string, integer, float,etc

Qualquer coisa estamos por aqui.


Responder

13/08/2004

Rockbilly

blz, + uma vez... obrigado!


Responder

13/08/2004

Paullus

// seu código da pesquisa
ADOQuery1.Active := true;

if ADOQuery1.RecordCount = 0 then
  ShowMessage(´Nome não encontrado´);


A propriedade [b:df1fd7eddb]RecordCount[/b:df1fd7eddb] de qualquer TDataSet te retorna a quantidade de registros informadas.


Responder

13/08/2004

Vinicius2k

A propriedade [b:50361998d7]RecordCount[/b:50361998d7] de qualquer TDataSet te retorna a quantidade de registros informadas.


Qualquer TDataSet não... exemplos :
IBX - IBQuery e IBDataSet, sem aplicação do FetchAll não retorna corretamente...
dbExpress - SQLQuery e SQLDataSet, se existirem parametros ou forem Selects com Joins, a leitura causa exceção...

T+


Responder

17/08/2004

Paullus

Qualquer TDataSet não... exemplos : IBX - IBQuery e IBDataSet, sem aplicação do FetchAll não retorna corretamente... dbExpress - SQLQuery e SQLDataSet, se existirem parametros ou forem Selects com Joins, a leitura causa exceção...


Dessa eu não sabia. :oops:
Vivendo e aprendendo... obrigado. :wink:


Responder

20/08/2020

Socrates Foschera

boa noite programadores

estou com uma duvida depois que verifico se o registro esta vazio

procedure TFrmRelacao_Veiculo.FormActivate(Sender: TObject);

begin

with dm.PesquisaRelacao_Veiculos do

begin

Close;
SQL.Clear;
SQL.Add('select * from relacao_veiculo');
sql.Add('where (nome)');
EDTPesquisa_Relacao_Veiculo.Text := FrmCadastro_Consulta_Cliente.Edit2.Text;
SQL.Add('like ('''+EDTPesquisa_Relacao_Veiculo.Text+''')');
open;

end;

if dm.PesquisaRelacao_Veiculos.IsEmpty then

begin

ShowMessage('Registro não encontrado');

end;

end;

a duvida é a seguinte como faço depois que ele deu a menssagem para ele fechar o form?
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar