Ir para conteúdo
Fórum Script Brasil
  • 0

Like Mostra Tudo


Renato Fonseca

Pergunta

olá galera bom dia !! queria saber se alguém pode me ajudar, estou fazendo uma busca no banco e mostrando na tela os registros estou usando o like e fazendo paginação mas não sei o que acontece ele traz tudo se digito A ele traz tudo que tem A e o que não tem também ?

abaixo o codigo :

<%
Response.CacheControl="no-cache" 
Response.AddHeader "Pragma","no-cache" 
Response.Expires = 0 
Response.Buffer = True

selec_opc=Request.Form("selec_opc")
busca=Request.Form("busca")



Response.Write busca

Const nTamanhoPagina = 1
Dim nPaginaAtual
Dim PaginaAtual
Dim nTotalPaginas
Dim SQL
Dim x

if Request.Querystring = "" then
   nPaginaAtual = 1
else
   nPaginaAtual = Cint(Request.Querystring("PaginaAtual")) 
   Select Case Request.Querystring("Submit")
     Case "Anterior"
        nPaginaAtual = nPaginaAtual - 1
     Case "Proxima"
        nPaginaAtual = nPaginaAtual + 1
   End Select
end if 

Dim con
Dim rs
Dim strCon
Set con = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
strCon ="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=SCC; Pwd=beta; Data Source=BETA"
con.Open strCon
rs.Cursorlocation = adUseClient
rs.CursorType = adOpenStatic
rs.CacheSize = nTamanhoPagina

 If selec_opc = "id_empresa" and IsNumeric(busca) then
        SQL= "Select * From SCC_EMPRESA Where ID_EMPRESA = '" & busca & "' Order by ID_EMPRESA"
    Else 'selec_opc = "nome_fantasia" Then
SQL= "Select ID_EMPRESA, NOME_FANTASIA, CEP From SCC_EMPRESA Where NOME_FANTASIA LIKE '%" & busca & "%" 'Order by Nome_Fantasia"


'"Select * From SCC_EMPRESA Where NOME_FANTASIA = '" & busca & "' Order by Nome_Fantasia"
    ' Else
    '    response.redirect("busca_empresa.asp?msg02= Digite apenas numeros para o ID Empresa !")
 End IF

rs.Open SQL, con 
rs.PageSize = nTamanhoPagina




If rs.EOF Then
    response.redirect("busca_empresa.asp?msg01= Empresa não encontrada !<br> <a href=cadastro_emp.asp> Clique aqui caso deseje cadastrar</a>")
    Response.End()

Else

 'rs.absolutePage = nPaginaAtual
   ' nTotalPaginas = rs.Pagecount
    'Session("id_empresa") =rs("ID_EMPRESA")
    'Session("nome_fantasia") =rs("NOME_FANTASIA")
    'Session("cep") =rs("CEP")
    
    
    'response.redirect("atualiza_empresa.asp")
    'Response.End()
'End If


    'close.con
    'Set nothing = con
    'Close.rs
    'Set nothing = rs
    
    %>

<!-- #Include file="ADOvb script:return valida_emp()" >
                             
                           <table style="width: 582px; height: 51px; left: 55px; position: absolute; top: 112px;" id="table" > <% rs.pagesize = nTamanhoPagina 
     If not (rs.eof) then
 rs.absolutePage = nPaginaAtual
 nTotalPaginas = rs.Pagecount
     %>
                           <tr>
                                    <td style="width: 318px" rowspan="12" >
                                        <ul id="nav">
                                            <li><a href="busca_empresa.asp"> Empresa</a> </li>
                                            <li><a href="busca_distribuidor.asp">Distribuidores</a> </li>
                                            <li><a href="funcionario.asp">Funcionário</a> </li>
                                            <li><a href="#">Cliente</a> </li>
                                            <li><a href="">Telefone Cliente</a> </li>
                                            <li><a href="">Tipo Telefone</a> </li>
                                            <li style="left: 0px; top: 0px"><a href="cargo.aspx">Cargo</a> </li>
                                        </ul>
                                    </td>
                                    <td style="width: 327px; height: 15px">
                                        <span >Id Empresa</span></td>
                                    <td style="width: 325px; height: 15px">
      <input name="id_empresa" value="<%=rs("id_empresa")%>" type="text"  style="width: 40px" maxlength="8" readonly="true"/>
                                        *</td>
                                </tr>
                                <tr>
                                    <td style="width: 327px; height: 15px">
                                        Nome Fantasia</td>
                                    <td style="width: 325px; height: 15px">
 <input name="nome_fantasia"  style="width: 205px" maxlength="50" value = "<%=rs("nome_fantasia")%>" >
                                        *</td>
                                </tr>
                                <tr>
                                    <td style="width: 327px">
                                        Cep</td>
                                    <td style="width: 325px"><input name="cep" value="<%=rs("cep")%>" type="text" id="Text3" style="width: 70px" maxlength="8" />
                                        *</td>
                                </tr>
                                <tr>
                                    <td style="width: 327px; height: 15px">
                                        </td>
                                    <td style="width: 325px; height: 15px">
                              
                                        </td>
                                </tr>
                                <tr>
                                    <td style="width: 327px">
                                        </td>
                                    <td style="width: 325px">
                               
                                        </td>
                                </tr>
                                <tr>
                                    <td style="width: 327px">
                                        </td>
                                    <td style="width: 325px">
                                
                                        </td>
                                </tr>
                                <tr>
                                    <td style="width: 327px">
                                        </td>
                                    <td style="width: 325px"> 
                                        </td>
                                </tr>
                                <tr>
                                    <td style="width: 327px">
                                        </td>
                                    <td style="width: 325px">
                                        </td>
                                </tr>
                                <tr>
                                    <td style="width: 327px">
                                        </td>
                                    <td style="width: 325px">
                                        </td>
                                </tr>
                                <tr>
                                    <td style="width: 327px">
                                        </td>
                                    <td style="width: 325px">
                                        </td>
                                </tr>
                                <tr>
                                    <td style="width: 327px">
                                        </td>
                                    <td style="width: 325px">
                                        </td>
                                </tr>
                                <tr>
                                    <td style="height: 22px; text-align: center;" colspan="2">

                                         
                                              <% response.write request.querystring("msg02")%>

<%If nPaginaAtual > 1 then %>
  <a href="<%=request.servervariables("SCRIPT_NAME")%>?PaginaAtual=<%=nPaginaAtual%>&Submit=Anterior">Anterior |</a>
  <%end if%>
  <%If nPaginaAtual <> nTotalPaginas then %>
  <a href="<%=request.servervariables("SCRIPT_NAME")%>?PaginaAtual=<%=nPaginaAtual%>&Submit=Proxima">Proxima</a>
  <%
End If
%>
                                    
                                        </td>
                                </tr>
                              <tr>
                                  <td rowspan="1" style="width: 318px">
                                  </td>
                                  <td style="height: 22px; text-align: center;" colspan="2">
<a href="java script:valida_emp();"></a> <a href="java script:valida_emp();"><img src="images/bt_atualizar.jpg" border="0" /></a>


  <a class="link" href="exclui_empresa.asp" onClick="document.forms..submit();return false">
  <img src="images/bt_excluir.jpg" border="0" /></a>
                            </tr>
                            </table>

                          </form>
                        </td>
                        <td style="width: 39px; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px; border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none; height: 290px;">
                            <img src="images/lat_direita.jpg" name="IMG2"  height="356" border="0" id="IMG2"  /></td>
                    </tr>
                    <tr>
                        <td colspan="3" style="height: 76px; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px;">
                            <img src="images/rodape.jpg" /></td>
                    </tr>
                    
                </table>
                
            </td>
        </tr>
        <tr>
        </tr>
        <tr>
        </tr>
<%
End If
End If
%>
<%
' Fechamos o recordset e liberamos a memória usada
rs.close
set rs=nothing
con.close
set con=nothing
%>

    </table>

</body>
</html>

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0
Guest --Renato --
Altera ai:

SQL= "Select ID_EMPRESA, NOME_FANTASIA, CEP From SCC_EMPRESA Where NOME_FANTASIA LIKE '%" & busca & "%' Order by Nome_Fantasia"

Alterei vi que o erro era a " mais ainda ele traz tudo com quando digito uma letra só, fiz um teste dentro do sql 2005 e funcionando certinho o que será ?

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...