Usuário com melhor resposta
Duvida.

Pergunta
-
Olá estou com uma duvida referente a busca aleatório.
O que to fazendo uma tela de busco com o campo txt já funciona com um select like.
Mas não to conseguindo entender como que vai para selecionar os outros campos e mostrar e resultado.
olha meu codigo.
<!--#include file="conexao.asp"-->
<%
Dim Pesquisa : Pesquisa = Request.Form("Pesquisa")
Dim Ordem : Ordem = Request.Form("radio_ordem")
Dim Pesqui : Pesqui = Request.Form("radio_pesquisa")
Dim acao : acao = Request.Form("acao")
Dim buscar_por : buscar_por = Request.Form("txt_Busca")
Dim RS_BUSCA
Dim tipopesquisa, tipoordem,tipobusca,valordapesquisa
' EXEMPLO
' tipopesquisa = "nome"
' tipoordem = "decrescente"
' tipobusca = "aleatorio"
' valordapesquisa = "Joao"
%>
<%
' COMEÇO DO TESTE ...
' FIM TESTE PARA SELECT "
%>
<table width="" border="0"" cellpadding="2" cellspacing="2">
<tr>
<td width="189" class="style7"> Campo de Pesquisa: <br/>
<select name="Pesquisa" class="campo" id="Pesquisa">
<option><-- Selecione --></option>
<option>Codigo</option>
<option>Nome</option>
</select> </td>
<td width="223" class="style7"> Ordem: <br />
<fieldset class="style8">
<input name="radio_ordem" type="radio" value="radio_ordem" />
Crescente
<input name="radio_ordem" type="radio" value="radio_ordem"/>
Decrescente
</fieldset></td>
</tr>
<tr>
<td class="style7">Pesquisa: <br />
<fieldset class="">
<input name="radio_pesqusa" type="radio" value="radio_pesqusa" />
Inicio da Frase
<input name="radio_pesqusa" type="radio" value="radio_pesqusa" />
Aleatório
</fieldset></td>
</tr>
<tr>
<td class="style7">Busca:<br />
<input name="txt_Busca" type="text" class="campo" id="txt_Busca" size="30" maxlength="50" /></td>
</tr>
</table>
<table width="" border="0" cellpadding="2" cellspacing="2">
<%
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA WHERE NOME_FANTASIA LIKE '%"&buscar_por&"%'"
IF tipopesquisa = "Pesquisa" THEN
SQL1 = SQL1 & " WHERE Pesquisa "
END IF
IF tipoordem = "radio_ordem" THEN
SQL1 = SQL1 & " ORDER BY DESC"
END IF
IF tipobusca = "r_pesqusa" then
SQL1 = SQL1 & " LIKE %'"&radio_pesqusa&"%'"
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.
'RS_BUSCA.open SQL,conexao
if RS_BUSCA.bof or RS_BUSCA.eof then %>
<tr class="style7">
<td width=""><div align="center" class="style8">
<div align="center" class="campo"><strong>SUA BUSCA NÃO RETORNOU RESULTADO!!</strong></div>
</div></td>
</tr>
<%else
End if%>
</table>
<table width="" border="0" bgcolor="">
<tr class="style8">
<td width="" class="style7"><strong><span class="style3 style6 style8">Codigo Empresa </span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Razão Social </span></strong></td>
<td width="" class="style7"><strong><span class="style9">Nome Fantasia</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cep</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Endereço</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Numero</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Complemento</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Bairro</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cidade</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Estado </span></strong></td>
<td width="" class="style7"><strong class="style8">E_mail</strong></td>
<td width="" class="style7"><strong class="style8">Telefone</strong></td>
</tr>
<tr class="style7">
<%
Do While RS_BUSCA.Eof=false
%>
<td height="" bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ID_EMPRESA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("RAZAO_SOCIAL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NOME_FANTASIA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CEP")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ENDERECO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NUMERO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("COMPLEMENTO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("BAIRRO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CIDADE")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ESTADO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("EMAIL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("TELEFONE")%></span></strong></td>
</tr>
<%
RS_BUSCA.MoveNext
Loop
End If
%>
Respostas
-
Da este erro porque vc não declaro a varável que deve estar recebendo o "this" da chamada de função.
O script tem que ser igual ao que esta abaixo.
<script language="javascript">
function somenteinteiro(campo){
if (document.getElementById("Pesquisa").options[2].selected == true)
{
var tam = campo.value.length;
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campo.value.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("Caractere inválido no campo \"Pesquisa\"\nDigite somente valores inteiros!");
campo.value = campo.value.substring(i,i-1)
campo.focus();
break;
}
}
}
}</script>
Abraços
Estevam
Todas as Respostas
-
Emerson seu código esta com alguns erros, por exemplo, os inputs radio voce esta definindo os value iguais, ou seja, na resposta do formulário independente de qual ele selecionar ele sempre vai receber o mesmo valor, mude isso para:
<input name="radio_ordem" type="radio" value="crescente" />Crescente
<input name="radio_ordem" type="radio" value="descrescente"/>Decrescentee
<input name="radio_pesqusa" type="radio" value="inicio" />Inicio da Frase
<input name="radio_pesqusa" type="radio" value="aleatorio" />AleatorioNos options dentro do select voce tem que definir os valores de cada option, se nao acontece a mesma coisa que expliquei acima, a proxima pagina neste caso nem vai receber valores.
<select name="Pesquisa" class="campo" id="Pesquisa">
<option><-- Selecione --></option>
<option value="codigo">Codigo</option>
<option value="nome">Nome</option>
</select>Ai depois voce faz esta verificaçao, para montar o SQL, se voce perceber no seu código voce usa a veriavel SQL e depois voce faz concatençao com uma q nao existe "SQL1". Entao deve ficar mais ou menos assim:
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA WHERE NOME_FANTASIA LIKE '%"&buscar_por&"%'"
IF Pesquisa = "nome" THEN
SQL = SQL & " WHERE nome "else
SQL = SQL & " WHERE codigo "
END IFIF Pesqui = "inicio" then
SQL = SQL & " LIKE %'"&buscar_por&"'"ELSE
SQL = SQL & " LIKE %"'&buscar_por&"'"
END IF
IF Ordem = "decrescente" THEN
SQL = SQL & " ORDER BY DESC"
END IF
è mais ou menos isso
Abraço
Estevam
-
Então fiz como vc pediu assim :
<%
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA WHERE NOME_FANTASIA LIKE '%"&buscar_por&"%'"IF Pesquisa = "None" THEN
SQL = SQL & "WHERE Nome "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
IF Pesqui = "inicio" then
SQL = SQL & " LIKE %'"&buscar_por&"'"
ELSE
SQL = SQL & " LIKE %'"&buscar_por&"'"
END IF
IF Ordem = "decrescente" THEN
SQL = SQL & " ORDER BY DESC"
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.
'RS_BUSCA.open SQL,conexao
mas deu este erro : Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near the keyword 'WHERE'.
/Chamado/consu_empresa.asp, line 231
-
Emerson é que tem um detalhe muito importante ai no meio, se o usuario escolher para fazer a busca pelo codigo então o LIKE no where nao pode ser realizado e também o SQL inicial já estava com a cláusula where o que com o seguimento do script ele acaba ficando com dois where, entao vc tera que fazer um outro if fica mais ou menos assim:
<%
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA"IF Pesquisa = "Nome" THEN
SQL = SQL & " WHERE Nome "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
if nome <> "" then
IF Pesqui = "inicio" then
SQL = SQL & " LIKE %'"&buscar_por&"'"
ELSE
SQL = SQL & " LIKE %'"&buscar_por&"'%"
END IF
else
SQL = SQL & " = " & buscar_porEND IF
IF Ordem = "decrescente" THEN
SQL = SQL & " ORDER BY DESC"
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.
'RS_BUSCA.open SQL,conexaoTesta com o código acima.
Abraços
Estevam
-
Kra ainda deu erro quando faço a seleção de no combobox ..
Tipo Razao Social .e click em busca ele da este erro !!
Microsoft OLE DB Provider for SQL Server error '80040e14'
Unclosed quotation mark after the character string '%%'WHERE RAZAO_SOCIAL'LIKE %''.
/Chamado/consu_empresa.asp, line 232
porque ?
-
Eu este erro tb ..quando eu alterei o formulario
<form id="consulta" name="consulta" method="post" action="consu_empresa.old.asp" onSubmit="return validar();">
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near '='.
/Chamado/consu_empresa.old.asp, line 243
-
-
Bom dia Estavam ..
Ai vai o codigo!!
<form id="consulta" name="consulta" method="post" action="consu_empresa.old.asp" onSubmit="return validar();">
<br />
<!--#include file="conexao.asp"-->
<%
Dim Pesquisa : Pesquisa = Request.Form("Pesquisa")
Dim Ordem : Ordem = Request.Form("radio_ordem")
Dim Pesqui : Pesqui = Request.Form("radio_pesquisa")
Dim acao : acao = Request.Form("acao")
Dim buscar_por : buscar_por = Request.Form("txt_Busca")
Dim RS_BUSCA
%>
<%
' COMEÇO DO TESTE ...
' FIM TESTE PARA SELECT "
%>
<table width="" border="0"" cellpadding="2" cellspacing="2">
<tr>
<td width="189" class="style7"> Campo de Pesquisa: <br/>
<select name="Pesquisa" class="campo" id="Pesquisa">
<option><-- Selecione --></option>
<option value="Codigo">Codigo</option>
<option value="Nome Fantasia">Nome Fantasia</option>
<option value="Razão Social">Razão Social</option>
</select> </td>
<td width="223" class="style7"> Ordem: <br />
<fieldset class="style8">
<input name="radio_ordem" type="radio" value="Crescente" />
Crescente
<input name="radio_ordem" type="radio" value="Descrescente"/>
Decrescente
</fieldset></td>
</tr>
<tr>
<td class="style7">Pesquisa: <br />
<fieldset class="">
<input name="radio_pesqusa" type="radio" value="Inicio" />
Inicio da Frase
<input name="radio_pesqusa" type="radio" value="Aleatorio" />
Aleatório
</fieldset></td>
</tr>
<tr>
<td class="style7">Busca:<br />
<input name="txt_Busca" type="text" class="campo" id="txt_Busca" size="30" maxlength="50" /></td>
</tr>
</table>
<table width="" border="0" cellpadding="2" cellspacing="2">
<%
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA"IF Pesquisa = "ID_EMPRESA" THEN
SQL = SQL & " WHERE ID_EMPRESA "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
if nome <> "" then
IF Pesqui = "Inicio" then
SQL = SQL & " LIKE %'"&buscar_por&"'"
ELSE
SQL = SQL & " LIKE %'"&buscar_por&"'%"
END IF
else
SQL = SQL & " = " & buscar_por
END IF
IF Ordem = "Decrescente" THEN
SQL = SQL & " ORDER BY DESC"
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.
'RS_BUSCA.open SQL,conexao
if RS_BUSCA.bof or RS_BUSCA.eof then %>
<tr class="style7">
<td width=""><div align="center" class="style8">
<div align="center" class="campo"><strong>SUA BUSCA NÃO RETORNOU RESULTADO!!</strong></div>
</div></td>
</tr>
<%else
End if%>
</table>
<table width="" border="0" bgcolor="">
<tr class="style8">
<td width="" class="style7"><strong><span class="style3 style6 style8">Codigo Empresa </span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Razão Social </span></strong></td>
<td width="" class="style7"><strong><span class="style9">Nome Fantasia</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cep</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Endereço</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Numero</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Complemento</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Bairro</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cidade</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Estado </span></strong></td>
<td width="" class="style7"><strong class="style8">E_mail</strong></td>
<td width="" class="style7"><strong class="style8">Telefone</strong></td>
</tr>
<tr class="style7">
<%
Do While RS_BUSCA.Eof=false
%>
<td height="" bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ID_EMPRESA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("RAZAO_SOCIAL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NOME_FANTASIA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CEP")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ENDERECO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NUMERO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("COMPLEMENTO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("BAIRRO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CIDADE")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ESTADO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("EMAIL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("TELEFONE")%></span></strong></td>
</tr>
<%
RS_BUSCA.MoveNext
Loop
End If
%>
<tr>
<td height="" colspan="13" bgcolor="#FFFFFF">
<div align="center">
<input name="bt_pesquisar" type="submit" class="botao" id="bt_pesquisar" value="Buscar"/>
<input name="bt_voltar" type="reset" class="botao" id="bt_voltar" value="Limpar"/>
<input name="acao" type="hidden" id="acao" value="buscar"/>
</div></td>
</tr>
</table>
</form>
</table></td>
</tr>
<tr>
<td height="15" colspan="3" bgcolor="#265490"></td>
</tr>
</table>
</table>
</body>
</html>
-
Emerson tente com este código abaixo, voce só tem que alterar os campos necessários para igual a de sua tabela, só tome cuidado ao altera-los, pois voce pode acabar bagunçando o código.
Abraços
Estevam
<form id="consulta" name="consulta" method="post" action="consu_empresa.old.asp" onSubmit="return validar();">
<br />
<!--#include file="conexao.asp"-->
<%
Dim Pesquisa : Pesquisa = Request.Form("Pesquisa")
Dim Ordem : Ordem = Request.Form("radio_ordem")
Dim Pesqui : Pesqui = Request.Form("radio_pesquisa")
Dim acao : acao = Request.Form("acao")
Dim buscar_por : buscar_por = Request.Form("txt_Busca")
Dim RS_BUSCA
%>
<%
' COMEÇO DO TESTE ...
' FIM TESTE PARA SELECT "
%>
<table width="" border="0"" cellpadding="2" cellspacing="2">
<tr>
<td width="189" class="style7"> Campo de Pesquisa: <br/>
<select name="Pesquisa" class="campo" id="Pesquisa">
<option><-- Selecione --></option>
<option value="Codigo">Codigo</option>
<option value="NomeFantasia">Nome Fantasia</option>
<option value="RazaoSocial">Razao Social</option>
</select> </td>
<td width="223" class="style7"> Ordem: <br />
<fieldset class="style8">
<input name="radio_ordem" type="radio" value="Crescente" />
Crescente
<input name="radio_ordem" type="radio" value="Descrescente"/>
Decrescente
</fieldset></td>
</tr>
<tr>
<td class="style7">Pesquisa: <br />
<fieldset class="">
<input name="radio_pesqusa" type="radio" value="Inicio" />
Inicio da Frase
<input name="radio_pesqusa" type="radio" value="Aleatorio" />
Aleatório
</fieldset></td>
</tr>
<tr>
<td class="style7">Busca:<br />
<input name="txt_Busca" type="text" class="campo" id="txt_Busca" size="30" maxlength="50" /></td>
</tr>
</table>
<table width="" border="0" cellpadding="2" cellspacing="2">
<%
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA"IF Pesquisa = "NomeFantasia" THEN
SQL = SQL & " WHERE NomeFantasia "
ELSEIF Pesquisa = "RazaoSocial" THENSQL = SQL & " WHERE RazaoSocial "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
IF Pesquisa = "NomeFantasia" OR Pesquisa = "RazaoSocial" then
IF Pesqui = "Inicio" then
SQL = SQL & " LIKE '%" & buscar_por & "'"
ELSE
SQL = SQL & " LIKE '%" & buscar_por & "%'"
END IFELSE
SQL = SQL & " = " & buscar_por
END IF
IF Ordem = "Decrescente" THENIF Pesquisa = "NomeFantasia" THEN
SQL = SQL & " ORDER BY NomeFantasia DESC"
ELSE Pesquisa = "RazaoSocial" THEN
SQL = SQL & " ORDER BY RazaoSocial DESC"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA DESC"
END IF
ELSE
IF Pesquisa = "NomeFantasia" THEN
SQL = SQL & " ORDER BY NomeFantasia"
ELSE Pesquisa = "RazaoSocial" THEN
SQL = SQL & " ORDER BY RazaoSocial"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA"
END IF
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.
'RS_BUSCA.open SQL,conexao
if RS_BUSCA.bof or RS_BUSCA.eof then %>
<tr class="style7">
<td width=""><div align="center" class="style8">
<div align="center" class="campo"><strong>SUA BUSCA NÃO RETORNOU RESULTADO!!</strong></div>
</div></td>
</tr>
<%else
End if%>
</table>
<table width="" border="0" bgcolor="">
<tr class="style8">
<td width="" class="style7"><strong><span class="style3 style6 style8">Codigo Empresa </span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Razão Social </span></strong></td>
<td width="" class="style7"><strong><span class="style9">Nome Fantasia</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cep</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Endereço</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Numero</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Complemento</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Bairro</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cidade</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Estado </span></strong></td>
<td width="" class="style7"><strong class="style8">E_mail</strong></td>
<td width="" class="style7"><strong class="style8">Telefone</strong></td>
</tr>
<tr class="style7">
<%
Do While RS_BUSCA.Eof=false
%>
<td height="" bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ID_EMPRESA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("RAZAO_SOCIAL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NOME_FANTASIA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CEP")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ENDERECO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NUMERO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("COMPLEMENTO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("BAIRRO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CIDADE")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ESTADO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("EMAIL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("TELEFONE")%></span></strong></td>
</tr>
<%
RS_BUSCA.MoveNext
Loop
End If
%>
<tr>
<td height="" colspan="13" bgcolor="#FFFFFF">
<div align="center">
<input name="bt_pesquisar" type="submit" class="botao" id="bt_pesquisar" value="Buscar"/>
<input name="bt_voltar" type="reset" class="botao" id="bt_voltar" value="Limpar"/>
<input name="acao" type="hidden" id="acao" value="buscar"/>
</div></td>
</tr>
</table>
</form>
</table></td>
</tr>
<tr>
<td height="15" colspan="3" bgcolor="#265490"></td>
</tr>
</table>
</table>
</body>
</html>
-
Olá Estevam
Fiz este codigo porém o que acontece quando eu faço a seleção no para cod e escolho a ordem decrescente ou crescente.
e click em busca ele da este erro .
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near the keyword 'ORDER'.
/Chamado/consu_empresa.old.asp, line 259
e quando eu faço a seleção para NOME_FANTASIA e faço a escolha a pesquisa para aleatorio.
e digito uma letra ele da este erro :
Microsoft OLE DB Provider for SQL Server error '80040e14'
Invalid column name 'd'.
/Chamado/consu_empresa.old.asp, line 259
<%
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA"IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " WHERE NOME_FANTASIA "
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " WHERE RAZAO_SOCIAL "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
IF Pesquisa = "NOME_FANTASIA" OR Pesquisa = "RAZAO_SOCIAL" then
IF Pesqui = "Inicio" then
SQL = SQL & " LIKE '%" & buscar_por & "'"
ELSE
SQL = SQL & " LIKE '%" & buscar_por & "%'"
END IF
ELSE
SQL = SQL & " = " & buscar_por
END IF
IF Ordem = "Decrescente" THEN
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA DESC"
ELSEif Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL DESC"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA DESC"
END IF
ELSE
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA"
END IF
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.
'RS_BUSCA.open SQL,conexao
if RS_BUSCA.bof or RS_BUSCA.eof then %>
<tr class="style7">
<td width=""><div align="center" class="style8">
<div align="center" class="campo"><strong>SUA BUSCA NÃO RETORNOU RESULTADO!!</strong></div>
</div></td>
</tr>
<%else
End if%>
</table>
<table width="" border="0" bgcolor="">
<tr class="style8">
<td width="" class="style7"><strong><span class="style3 style6 style8">Codigo Empresa </span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Razão Social </span></strong></td>
<td width="" class="style7"><strong><span class="style9">Nome Fantasia</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cep</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Endereço</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Numero</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Complemento</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Bairro</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cidade</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Estado </span></strong></td>
<td width="" class="style7"><strong class="style8">E_mail</strong></td>
<td width="" class="style7"><strong class="style8">Telefone</strong></td>
</tr>
<tr class="style7">
<%
Do While RS_BUSCA.Eof=false
%>
<td height="" bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ID_EMPRESA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("RAZAO_SOCIAL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NOME_FANTASIA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CEP")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ENDERECO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NUMERO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("COMPLEMENTO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("BAIRRO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CIDADE")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ESTADO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("EMAIL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("TELEFONE")%></span></strong></td>
</tr>
<%
RS_BUSCA.MoveNext
Loop
End If
%>
<tr>
<td height="" colspan="13" bgcolor="#FFFFFF">
<div align="center">
<input name="bt_pesquisar" type="submit" class="botao" id="bt_pesquisar" value="Buscar"/>
<input name="bt_voltar" type="reset" class="botao" id="bt_voltar" value="Limpar"/>
<input name="acao" type="hidden" id="acao" value="buscar"/>
</div></td>
</tr>
</table>
</form>
</table></td>
</tr>
<tr>
<td height="15" colspan="3" bgcolor="#265490"></td>
</tr>
</table>
</table>
</body>
</html>
-
Emerson seu select esta como este aki?
<select name="Pesquisa" class="campo" id="Pesquisa">
<option>-- Selecione --</option>
<option value="Codigo">Codigo</option>
<option value="NOME_FANTASIA">Nome Fantasia</option>
<option value="RAZAO_SOCIAL">Razao Social</option>
</select>Abraços
Estevam
-
Estevam .
Ta acontecendo o seguinte quando eu faço a seleção NOME_FANTASIA E DEPOIS PEÇO PARA ORDERAR COMO CRESCENTE .
Ele vem porém quando faço a mesma seleção e peço para ordernar em decrescente ele não vem ..Continua a mesma coisa ..
Isso também equivale para Razao Social.!
Olha o codigo !!
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " WHERE NOME_FANTASIA "
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " WHERE RAZAO_SOCIAL "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
IF Pesquisa = "NOME_FANTASIA" OR Pesquisa = "RAZAO_SOCIAL" then
IF Pesqui = "Inicio" then
SQL = SQL & " LIKE '%" & buscar_por & "'"
ELSE
SQL = SQL & " LIKE '%" & buscar_por & "%'"
END IF
ELSE
SQL = SQL & " = " & buscar_por
END IF
IF Ordem = "Decrescente" THEN
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL DESC"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA DESC"
END IF
ELSE
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL DESC"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA DESC"
END IF
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.
'RS_BUSCA.open SQL,conexao
IF RS_BUSCA.bof or RS_BUSCA.eof THEN %>
-
Emerson, novamente voce alterou algumas linhas do que eu tinha te passado veja as linhas abaixo que é do jeito que deve ficar e compare com as que voce enviou!
IF Ordem = "Decrescente" THEN
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA DESC"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL DESC"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA DESC"
END IF
ELSE
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA"
END IF
END IFAbraços
Estevam
-
Blz ..
Mas quando eu faço a seleção do cod e escolho crescente ou decrescente e mando busca ele da este erro !!
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near the keyword 'ORDER'.
/Chamado/consu_empresa.old.asp, line 253
-
Vamos por parte Emerson, no momento atual o problema só esta ocorrendo quando voce faz a seleçao por código certo? Por razao e por nome fantasia funciona ok???
Deixa eu lhe perguntar quando voce faz a busca por código ele pode trazer mais de uma empresa ou ele só vai trazer a empresa cadastrada no código pesquisado?
Abraços
Estevam
-
Bom dia Estavam.
Então nome Fantasia e Razão tudo funciona.
O codigo tem que fazer a mesma coisa que o nome e razao .
Tipo eu seleciono cod e faço a ordem por decrescente ou crescente ele vai fazer isso.
Se eu digitar o codigo ele vai trazer se o codigo que eu digitei .
Tenho outra duvida também quando eu seleciono Razão Social e faço Pesquisa Inicio da Frase
e digito a letra: "e" ele não traz as empresas cadastradas que tem de inicio a letra "e".
Abraço.
-
Bom dia Emerson!
Ok nome fantasia e razao funciona, legal, agora o que quero entender é o seguinte, voce faz a pesquisa por código certo? por exemplo se voce digitar o código 25, voce quer que traga todas as empresas que tem o código 25 ou vai trazer somente a empresa com código 25? Como esta o campo código no seu banco de dados, esta como inteiro ou como string?
Quanto a pesquisa por "Inicio da Frase", voce sabe se seu banco ta diferenciando maiscúlas e minúsculas? Já tentou fazer a pesquisa com "inicio da Frase" mas com letra maiscúla, tipo "E"?
Abraço
Estevam
-
Então tem que trazer a empresa que tem o codigo 25.
O campo codigo ta como inteiro no banco .
Refente ao "Inicio da frase" faço pesquisa como "inicio da frase " coloco a letra "E" em maiscúla porém ele não traz .
Agora quando eu faço a seleção e aleatório ele traz e digito a letra "E" ..ele traz .Ai vai o codigo :
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA"IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " WHERE NOME_FANTASIA "
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " WHERE RAZAO_SOCIAL "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
IF Pesquisa = "NOME_FANTASIA" OR Pesquisa = "RAZAO_SOCIAL" then
IF Pesqui = "Inicio" then
SQL = SQL & " LIKE '%" & buscar_por & "'"
ELSE
SQL = SQL & " LIKE '%" & buscar_por & "%'"
END IF
ELSE
SQL = SQL & " = " & buscar_por
END IF
IF Ordem = "Decrescente" THEN
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA DESC"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL DESC"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA DESC"
END IF
ELSE
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA"
END IF
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL. -
Emerson, realmente na busca por inicio da frase o código esta errado e esta buscando no final da frase abaixo vai corrigido e alterei a parte do código faça um teste.
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA"IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " WHERE NOME_FANTASIA "
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " WHERE RAZAO_SOCIAL "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
IF Pesquisa = "NOME_FANTASIA" OR Pesquisa = "RAZAO_SOCIAL" then
IF Pesqui = "Inicio" then
SQL = SQL & " LIKE '" & buscar_por & "%'"
ELSE
SQL = SQL & " LIKE '%" & buscar_por & "%'"
END IF
ELSE
SQL = SQL & " = " & buscar_por
END IF
IF Ordem = "Decrescente" THEN
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA DESC"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL DESC"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA DESC"
END IF
ELSE
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL"ELSE
SQL = SQL & ""
END IF
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.Abraços
Estevam
-
Entendi .,
Mas refente ao codigo o que podemos fazer.
pensei em fazer uma função o que acha ?
Tipo quando eu selecionar no combobox o codigo no campo txt informar para o usuario se ele digitar letra ...
Como podemos fazer isso ..
TAva fazendo assim ?
function campo(){
if (consulta.Codigo.value ==""){
alert('POR FAVOR PREENCHA O CAMPO COM NUMERO!');
consulta.Codigo.focus(document.consulta.Codigo.style.background ="#FFFFCC");
return false;
}
}
</script> -
A parte do de busca pelo código tente colocar o abaixo para ver se funciona:
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA"IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " WHERE NOME_FANTASIA "
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " WHERE RAZAO_SOCIAL "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
IF Pesquisa = "NOME_FANTASIA" OR Pesquisa = "RAZAO_SOCIAL" then
IF Pesqui = "Inicio" then
SQL = SQL & " LIKE '" & buscar_por & "%'"
ELSE
SQL = SQL & " LIKE '%" & buscar_por & "%'"
END IF
ELSE
SQL = SQL & " = " & buscar_por
END IF
IF Ordem = "Decrescente" THEN
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA DESC"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL DESC"
ELSE
SQL = SQL & ""
END IF
ELSE
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL"ELSE
SQL = SQL & ""
END IF
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.Abraços
Estevam
-
Então o que acontece quando eu faço a seleção do codigo e faço a ordem
Ele fica com este erro :
Microsoft OLE DB Provider for SQL Server error '80040e14'Incorrect syntax near '='.
/Chamado/consu_empresa.old.asp, line 272
E quando faço a busca por codigo e digito a letra "D" o meu txt ele fica com este erro !
Microsoft OLE DB Provider for SQL Server error '80040e14'Invalid column name 'd'.
/Chamado/consu_empresa.old.asp, line 272
O que acha de fazer uma função ?
-
Emerson, tente alterar a linha abaixo para e veja o que acontece, verifica se retorna o mesmo erro?
SQL = SQL & " = " & buscar_por
Troca para esta: (Obs.: Troca o 25 por algum id de empresa cadastrada ai)
SQL = SQL & " = 25"
E quanto ao buscar pelo código digitando o "D", isto nao é possivel pois seu banco esta configurado para receber inteiro, entao nao vai conseguir comparar uma string com um inteiro, entendeu?
Abraços
Estevam
-
Entendi .
Mas Estevam neste caso o que acha de fazer um função para alertar o usuario que ele da digitando uma letra quando ele faz a seleção no combobox.
<script language="javascript">
function campo(){
if (consulta.ID_EMPRESA.value ==""){
alert('POR FAVOR PREENCHA O SOMENTE COM NÚMERO!');
consulta.ID_EMPRESA.focus(document.consulta.ID_EMPRESA.style.background ="#FFFFCC");
return false;
}
}
</script>Tenho que colocar onKeyPress="return campo(event);"/> no campo.
E assim mesmo .?
-
Emerson tenho a funçao abaixo, dei uma adaptada para seu caso ve se funciona!
Voce pode coloar ela no key press sim, só vai ficar dando mensagem de erro toda hora que ele digitar um caractere nao valido.
onkeypress="somenteinteiro(this);")
Script Abaixo:
function somenteinteiro(campo)
{if (document.getElementById("Pesquisa").options[2].selected == true)
{
var tam = campo.length;
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campo.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("Caractere inválido no campo \"Pesquisa\"\nDigite somente valores inteiros!");
document.getElementById("ID_EMPRESA").focus();
break;
}
}
}
}Abraços
Estevam
-
Estevam ainda com está função deu erro !
Campo faço a seleção do codigo e digito uma letra aparece isso :
Microsoft OLE DB Provider for SQL Server error '80040e14'
Invalid column name 'd'.
/Chamado/consu_empresa.old.asp, line 296
aqui e o campo Busca :
<input name="txt_Busca" type="text" class="campo" id="txt_Busca" size="30" maxlength="50" onkeypress="somenteinteiro(this);")/></td>
-
Emerson troca a funçao que lhe envie por esta abaixo, por a que estou te passando agora eu testei e veja se da tudo certo. A funçao deve garantir que antes que o form seja enviando e o cliente ter escolhido a pesquisa por código, que nao havera tipo de caractere na busca.
Testa ai!!
function somenteinteiro(campo)
{
if (document.getElementById("Pesquisa").options[2].selected == true)
{
var tam = campo.value.length;
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campo.value.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("Caractere inválido no campo \"Pesquisa\"\nDigite somente valores inteiros!");
campo.value = campo.value.substring(i,i-1)
campo.focus();
break;
}
}
}
}Abraços
Estevam
-
Estevam ainda deu o mesmo erro vou passar o cod inteiro da tela..
olha o eero :
Microsoft OLE DB Provider for SQL Server error '80040e14'
Invalid column name 'd'.
/Chamado/consu_empresa.old.asp, line 302
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>:: Briefing _________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________</title>
<style type="text/css">body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
A.menu_sup {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #ffffff;
}A.menu_sup:link {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #ffffff;
}A.menu_sup:hover {
text-decoration: none;
color: #dadada;}
.campo {BACKGROUND: #f8f8f8;
COLOR: #265490;
BORDER-BOTTOM: #265490 1px solid;
BORDER-LEFT: #EFEFEF 1px solid;
BORDER-RIGHT: #265490 1px solid;
BORDER-TOP: #EFEFEF 1px solid;
FONT-SIZE: 10px;
height : 20;
}a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #265490;
}a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
color: #999999;
}
a:active {
text-decoration: none;
}.style5 {color: #FFFFFF}
.style8 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #255691;
}
.style7 {font-size: 10px; color: #1C406C; font-family: Verdana, Arial, Helvetica, sans-serif;}
.botao {BACKGROUND: #f8f8f8;
COLOR: #265490;
BORDER-BOTTOM: #265490 1px solid;
BORDER-LEFT: #EFEFEF 1px solid;
BORDER-RIGHT: #265490 1px solid;
BORDER-TOP: #EFEFEF 1px solid;
FONT-SIZE: 10px;
width:80px;
height : 20;
}
.style9 {color: #255691}
</style></head><body>
<table width="" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="502" height="100" background="images/topo_01.jpg"><img src="images/chamado_2_01.jpg" width="502" height="99" /></td>
<td width="100%" background="images/topo_01.jpg"> </td>
<td width="271"><img src="images/chamado_2_03.jpg" width="271" height="100" /></td>
</tr>
<tr>
<td height="1" colspan="3" bgcolor="#F8f8f8"></td>
</tr>
<tr>
<td colspan="3" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="1%" bgcolor="#265490"> </td>
<td width="100%" height="22" valign="top" bgcolor="#265490"><a href="cadastro.html" class="menu_sup"> Cadastro</a><span class="style5"> | </span><a href="processos.html" class="menu_sup">Processos</a> <span class="style5">| </span><a href="seguranca.html" class="menu_sup">Segurança</a> <span class="style5">|</span> <a href="relatorios.html" class="menu_sup">Relatórios</a> <span class="style5">|</span> <a href="gerenciamento.html" class="menu_sup">Gerenciamento</a> <span class="style5">|</span> <a href="logout.asp" class="menu_sup">Sair</a></td>
</tr>
</table></td>
</tr>
<tr>
<td height="1" colspan="3" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="" colspan="3"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20%" valign="top" bgcolor="#FFFFFF"><br />
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>
<td bgcolor="#FFFFFF"><img src="images/cadastro.jpg" width="136" height="28" /><br />
<img src="images/menuMiniBullet.gif" width="4" height="4" /> <a href="#">Empresas </a><br />
<img src="images/menuMiniBullet.gif" width="4" height="4" /> <a href="#">Funcionários</a><br />
<img src="images/menuMiniBullet.gif" width="4" height="4" /> <a href="#">Clientes</a><br />
<img src="images/menuMiniBullet.gif" width="4" height="4" /> <a href="#">Cargos</a><br />
<img src="images/menuMiniBullet.gif" width="4" height="4" /> <a href="#">Tipos de telefone </a></td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
<td width="" background="images/fd.jpg" bgcolor="#CCCCCC"> </td>
<td width="79%" valign="top" bgcolor="#FFFFFF">
<!-- <form action="consu_new.asp" method="post" name="consu_new" id="acao" onSubmit="return valida();" >-->
<script language="javascript">function validar(){
consulta.txt_Busca.focus(document.consulta.txt_Busca.style.background ="");
consulta.Pesquisa.focus(document.consulta.Pesquisa.style.background ="");
if (consulta.Pesquisa.value ==""){
alert('POR FAVOR PREENCHA O CAMPO PESQUISA!');
consulta.Pesquisa.focus(document.consulta.Pesquisa.style.background ="#FFFFCC");
return false;
}
if (consulta.txt_Busca.value ==""){
alert('POR FAVOR PREENCHA O CAMPO BUSCA!');
consulta.txt_Busca.focus(document.consulta.txt_Busca.style.background ="#FFFFCC");
return false;
}
// if (consulta.Pesquisa.value ="ID_CODIGO"){
// alert('POR FAVOR PREENCHA O SOMENTE COM NÚMERO!');
// consulta.Pesquisa.focus(document.consulta.Pesquisa.style.background ="#FFFFCC");
//
// }else{
// (consulta.Pesquisa.value ="NOME_FANTASIA")
// consulta.txt_Busca.focus(document.consulta.txt_Busca.style.background ="#FFFFCC");
// return false;
// }
}
</script>
<script language="javascript">function somenteinteiro(campo)
{
if (document.getElementById("Pesquisa").options[2].selected == true)
{
var tam = campo.value.length;
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campo.value.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("Caractere inválido no campo \"Pesquisa\"\nDigite somente valores inteiros!");
campo.value = campo.value.substring(i,i-1)
campo.focus();
break;
}
}
}
}</script>
<form id="consulta" name="consulta" method="post" action="consu_empresa.old.asp" onsubmit=" return validar();">
<br />
<!--#include file="conexao.asp"-->
<%
Dim Pesquisa : Pesquisa = Request.Form("Pesquisa")
Dim Ordem : Ordem = Request.Form("radio_ordem")
Dim Pesqui : Pesqui = Request.Form("radio_pesquisa")
Dim acao : acao = Request.Form("acao")
Dim buscar_por : buscar_por = Request.Form("txt_Busca")
Dim RS_BUSCA
%>
<table width="" border="0"" cellpadding="2" cellspacing="2">
<tr>
<td width="189" class="style7"> Campo de Pesquisa: <br/>
<select name="Pesquisa" class="campo" id="Pesquisa">
<option><-- Selecione --></option>
<option value="ID_EMPRESA">Codigo</option>
<option value="NOME_FANTASIA">Nome Fantasia</option>
<option value="RAZAO_SOCIAL">Razão Social</option>
</select> </td>
<td width="223" class="style7"> Ordem: <br />
<fieldset class="style8">
<input name="radio_ordem" type="radio" value="Crescente" checked="checked" />
Crescente
<input name="radio_ordem" type="radio" value="Decrescente"/>
Decrescente
</fieldset></td>
</tr>
<tr>
<td class="style7">Pesquisa: <br />
<fieldset class="">
<input name="radio_pesquisa" type="radio" value="Inicio" checked="checked"/>
Inicio da Frase
<input name="radio_pesquisa" type="radio" value="Aleatorio"/>
Aleatório
</fieldset></td>
</tr>
<tr>
<td class="style7">Busca:<br />
<input name="txt_Busca" type="text" class="campo" id="txt_Busca" size="30" maxlength="50" onkeypress="somenteinteiro"/></td>
</tr>
</table>
<table width="" border="0" cellpadding="2" cellspacing="2">
<%
IF acao = "buscar" THEN
SQL = "SELECT ID_EMPRESA, RAZAO_SOCIAL, NOME_FANTASIA, CEP, ENDERECO, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, ESTADO, EMAIL, TELEFONE FROM EMPRESA"
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " WHERE NOME_FANTASIA "
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " WHERE RAZAO_SOCIAL "
ELSE
SQL = SQL & " WHERE ID_EMPRESA "
END IF
IF Pesquisa = "NOME_FANTASIA" OR Pesquisa = "RAZAO_SOCIAL" then
IF Pesqui = "Inicio" then
SQL = SQL & " LIKE '" & buscar_por & "%'"
ELSE
SQL = SQL & " LIKE '%" & buscar_por & "%'"
END IF
ELSE
SQL = SQL & " = " & buscar_por
END IF
IF Ordem = "Decrescente" THEN
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA DESC"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL DESC"
ELSE
SQL = SQL & " ORDER BY ID_EMPRESA DESC"
END IF
ELSE
IF Pesquisa = "NOME_FANTASIA" THEN
SQL = SQL & " ORDER BY NOME_FANTASIA"
ELSEIF Pesquisa = "RAZAO_SOCIAL" THEN
SQL = SQL & " ORDER BY RAZAO_SOCIAL"
ELSE
SQL = SQL & ""
END IF
END IF
SET RS_BUSCA = conexao.execute(SQL)' SET RS_BUSCA RECOR SET = MINHA CONEXÃO EXECUTE O MEU COMANDO SQL.
'RS_BUSCA.open SQL,conexao
IF RS_BUSCA.bof or RS_BUSCA.eof THEN %>
<tr class="style7">
<td width=""><div align="center" class="style8">
<div align="center" class="campo"><strong>SUA BUSCA NÃO RETORNOU RESULTADO!!</strong></div>
</div></td>
</tr>
<%ELSE
END IF%>
</table>
<table width="" border="0" bgcolor="">
<tr class="style8">
<td width="" class="style7"><strong><span class="style3 style6 style8">Codigo Empresa </span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Razão Social </span></strong></td>
<td width="" class="style7"><strong><span class="style9">Nome Fantasia</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cep</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Endereço</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Numero</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Complemento</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Bairro</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Cidade</span></strong></td>
<td width="" class="style7"><strong><span class="style3 style6 style8">Estado </span></strong></td>
<td width="" class="style7"><strong class="style8">E_mail</strong></td>
<td width="" class="style7"><strong class="style8">Telefone</strong></td>
</tr>
<tr class="style7">
<%
Do While RS_BUSCA.Eof=false
%>
<td height="" bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ID_EMPRESA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("RAZAO_SOCIAL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NOME_FANTASIA")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CEP")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ENDERECO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("NUMERO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("COMPLEMENTO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("BAIRRO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("CIDADE")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("ESTADO")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("EMAIL")%></span></strong></td>
<td bgcolor="#FFFFFF" class="style7"><strong><span class="style8"><%=RS_BUSCA("TELEFONE")%></span></strong></td>
</tr>
<%
RS_BUSCA.MoveNext
Loop
End If
%>
<tr>
<td height="" colspan="13" bgcolor="#FFFFFF">
<div align="center">
<input name="bt_pesquisar" type="submit" class="botao" id="bt_pesquisar" value="Buscar"/>
<input name="bt_voltar" type="reset" class="botao" id="bt_voltar" value="Limpar"/>
<input name="acao" type="hidden" id="acao" value="buscar"/>
</div></td>
</tr>
</table>
</form>
</table></td>
</tr>
<tr>
<td height="15" colspan="3" bgcolor="#265490"></td>
</tr>
</table>
</table>
</body>
</html>
-
-
então linha 302 ele faz a busca se não achar ele manda a mensagem de aviso, falando que a SUA BUSCA NÂO;O RETORNOU RESULTADO!!
Então o que faço coloco a função . e vou no combobox onde escolho o cod em seguinta eu vou no busca e digito a letra "T", ai ele da o erro .
Então tava vendo aqui tb ..tem um erro .assim .
linha 176
caractere = 4
erro = 'value' é nulo ou não objeto
E aqui eu acho !!!
</script>
<script language="javascript">
function somenteinteiro(campo)
{
if (document.getElementById("Pesquisa").options[2].selected == true)
{
var tam = campo.value.length; esta e a linha com erro !!!!
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campo.value.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("Caractere inválido no campo \"Pesquisa\"\nDigite somente valores inteiros!");
campo.value = campo.value.substring(i,i-1)
campo.focus();
break;
}
}
}
}</script>
-
Emerson voce fez a chamada da funçao JavaScript incorretamente, voce fez assim:
<input name="txt_Busca" type="text" class="campo" id="txt_Busca" size="30" maxlength="50" onkeypress="somenteinteiro"/></td>
E deve ficar assim:
<input name="txt_Busca" type="text" class="campo" id="txt_Busca" size="30" maxlength="50" onkeypress="somenteinteiro(this);"/></td>
Abraços
Estevam
-
KRA AINDA CONTINUA COM O MESMO ERRO ..
ESTA E A FUNÇÃO..
</script>
<script language="javascript">
function somenteinteiro(){
if (document.getElementById("Pesquisa").options[2].selected == true)
{
var tam = campo.value.length;
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campo.value.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("Caractere inválido no campo \"Pesquisa\"\nDigite somente valores inteiros!");
campo.value = campo.value.substring(i,i-1)
campo.focus();
break;
}
}
}
}</script>
AQUI NO TXT = <input name="txt_Busca" type="text" class="campo" id="txt_Busca" size="30" maxlength="50" onkeypress="somenteinteiro(this);"/>
Microsoft OLE DB Provider for SQL Server error '80040e14'
Invalid column name 'd'.
/Chamado/consu_empresa.old.asp, line 293
abraço.
-
-
Da este erro porque vc não declaro a varável que deve estar recebendo o "this" da chamada de função.
O script tem que ser igual ao que esta abaixo.
<script language="javascript">
function somenteinteiro(campo){
if (document.getElementById("Pesquisa").options[2].selected == true)
{
var tam = campo.value.length;
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campo.value.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("Caractere inválido no campo \"Pesquisa\"\nDigite somente valores inteiros!");
campo.value = campo.value.substring(i,i-1)
campo.focus();
break;
}
}
}
}</script>
Abraços
Estevam
-
Bom dia Estevam.
Então fiz isso ontem tb..
Mas ainda este codigo da erro, quando eu faço a seleção do cod e digito no banco busca uma letra.
Continua o mesmo erro ...
Fiz o cod igual vc falou !
<script language="javascript">
function somenteinteiro(campo){
if (document.getElementById("Pesquisa").options[2].selected == true)
{
var tam = campo.value.length;
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campo.value.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("Caractere inválido no campo \"Pesquisa\"\nDigite somente valores inteiros!");
campo.value = campo.value.substring(i,i-1)
campo.focus();
break;
}
}
}
}</script>
==========================================
Olha o erro :
Microsoft OLE DB Provider for SQL Server error '80040e14'
Invalid column name 'd'.
/Chamado/consu_empresa.old.asp, line 292
-
Emerson ai que esta o problema, como voce já sabe se voce enviar para a consulta uma pesquisa com letras (string) e a consulta estiver esperando um número inteiro vai gerar erro certo? O propósito da funçao é nao permitir a entrada de caracteres que nao sejam números inteiros.
No ententando este erro que voce mostra acima é de pesquisa no banco (vinculado ao ASP), já se a funçao JS nao esta fazendo o que deve fazer deve estar dando um erro de script ná pagina, ai preciso saber qual o erro exato que da ná funçao JS.
Agora vamos mudar para ver se resolve o problema! Vamos troca a funçao e a chamada da funçao, em vez de chamarmos a funçao no campo, nós vamos chamar no form ok?
Entao vc deve retirar o comando "onkeypress" do campo text e incluir na tag form o "onsubmit" assim:
<form name="formularioteste" action="recebe.html" method="post" onsubmit="return somenteinteiro();" />
Troque a funçao para esta abaixo:
<script language="javascript">
function somenteinteiro(){
campobusca = document.getElementById("txt_Busca");
campopesquisa = document.getElementById("Pesquisa");
var retorno = true;
if (campopesquisa.options[2].selected == true)
{
var tam = campobusca.value.length;
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campobusca.value.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("Caractere inválido no campo \"Pesquisa\".\nVoce escolheu consulta por Código.\nDigite somente valores inteiros!");
campobusca.value = ""campobusca.focus();
retorno = false;
break;
}
}
}
return retorno;
}</script>
Bom testa ai agora.
Abraços
Estevam
-
Olá Estevam .
Então kra a função tava certa mesmo ...
eu que tava passando o errado ..
Agora foi, ficou assim .
ISSO AQUE O MEU CAMPO PESQUISA ! OPTIONS AQUI É 1 SÓ FIZ ISSO .....
<select name="Pesquisa" class="campo" id="Pesquisa">
<option><-- Selecione --></option>
<option value="ID_EMPRESA">Codigo</option>
<option value="NOME_FANTASIA">Nome Fantasia</option>
<option value="RAZAO_SOCIAL">Razão Social</option>
</select></td><script language="javascript">
// FUNÇÃO PARA VERIFICAR CAMPO.
function somenteinteiro(campo){
if (document.getElementById("Pesquisa").options[1].selected == true) "aqui que eu fiz alteração coloquei a options [1]"
{
var tam = campo.value.length;
var charunicode;
for (var i = 0;i<tam;i++)
{
charunicode = campo.value.substring(i,i+1).charCodeAt();
if ((charunicode < 48) || (charunicode > 57))
{
window.alert("CARACTERE INVÁLIDO NO CAMPO BUSCA,VOCÊ ESCOLHEU A CONSULTA POR CÓDIGO!");
campo.value = campo.value.substring(i,i-1)
campo.focus;
break;
}
}
}
}</script>
-