Registro não encontrado!
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:
tinha feito algo como:
if ADOQuery1.EOF then
blabla
mas não sei se está coerente isso, alguem pode me dar uma luz?
obrigado.
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
Curtidas 0
Respostas
Melo
10/08/2004
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
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
GOSTEI 0
Rockbilly
10/08/2004
brigado melo, vou tentar fazer isso!
GOSTEI 0
Rockbilly
10/08/2004
não deu certo, ele sempre dá ´Registro não encotrado!´, olhem meu código:
e tb:
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;
GOSTEI 0
Rockbilly
10/08/2004
desculpa, os códigos são esses:
e tb:
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;
GOSTEI 0
Macario
10/08/2004
desculpa, os códigos são esses:
e tb:
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;
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]
GOSTEI 0
Rockbilly
10/08/2004
Oi gente fina, vou testa isso e qq coisa posto... vlw a atenção!
GOSTEI 0
Macario
10/08/2004
Há uma dica pro seu código.
Tente assim:
ou assim:
na linha em vermelho voce usa atribui o parametro conforme o tipo do dado: string, integer, float,etc
Qualquer coisa estamos por aqui.
Tente assim:
[color=green:43e4c9dac0][/color: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´);
ou assim:
[color=green:43e4c9dac0][/color: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´);
na linha em vermelho voce usa atribui o parametro conforme o tipo do dado: string, integer, float,etc
Qualquer coisa estamos por aqui.
GOSTEI 0
Rockbilly
10/08/2004
blz, + uma vez... obrigado!
GOSTEI 0
Paullus
10/08/2004
// 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.
GOSTEI 0
Vinicius2k
10/08/2004
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+
GOSTEI 0
Paullus
10/08/2004
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:
GOSTEI 0
Socrates Foschera
10/08/2004
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?
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?
GOSTEI 0