Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Buenas pessoal,
Estou com uma dúvida num sistema que fiz.
É uma tela inicial de notícias, porem nele está aparecendo o seguinte erro:
>
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression 'imagem <> '' and indice <>'.
/admin/noticias/site/ExibirHome.asp, line 113
O código destá página é:
<!-- #Include Virtual="/admin/comum/includes/conexao.asp"-->
<!-- #Include Virtual="/admin/comum/includes/parametros.asp"-->
<!-- #Include Virtual="/admin/comum/funcoes/asphtml.asp"-->
<%
Function HTMLEspeciais(sString)
If (sString <> "") Then
sString = Replace(sString, "á", "á")
sString = Replace(sString, "â", "â")
sString = Replace(sString, "Ã ", "à")
sString = Replace(sString, "ã", "ã")
sString = Replace(sString, "ç", "ç")
sString = Replace(sString, "é", "é")
sString = Replace(sString, "ê", "ê")
sString = Replace(sString, "Ã", "í")
sString = Replace(sString, "ó", "ó")
sString = Replace(sString, "ô", "ô")
sString = Replace(sString, "õ", "õ")
sString = Replace(sString, "ú", "ú")
sString = Replace(sString, "ü", "ü")
sString = Replace(sString, "Ã", "Á")
sString = Replace(sString, "Â", "Â")
sString = Replace(sString, "À", "À")
sString = Replace(sString, "Ã", "Ã")
sString = Replace(sString, "Ç", "Ç")
sString = Replace(sString, "É", "É")
sString = Replace(sString, "Ê", "Ê")
sString = Replace(sString, "Ã", "Í")
sString = Replace(sString, "Ó", "Ó")
sString = Replace(sString, "Ô", "Ô")
sString = Replace(sString, "Õ", "Õ")
sString = Replace(sString, "Ú", "Ú")
sString = Replace(sString, "Ü", "Ü")
sString = Replace(sString, """", """) '"
sString = Replace(sString, "<", "<") '<
sString = Replace(sString, ">", ">") '>
End If
HTMLEspeciais = sString
End Function
set Sql_Noticia = conn.execute("SELECT * FROM noticias WHERE imagem <> '' ORDER BY indice desc")
If not Sql_Noticia.eof And Not Sql_Noticia.bof Then
set Sql_Ttl = conn.execute("SELECT COUNT(indice) AS Ttl FROM noticias WHERE imagem <> ''")
sTtl = Sql_Ttl("Ttl")
If sTtl = 1 Then
sTtl = 1
ElseIf sTtl = 2 Then
sTtl = 2
Else
sTtl = 3
End If
i = 1
while not Sql_Noticia.eof And i < sTtl
sString = Sql_Noticia("titulo")
titulo = HTMLEspeciais(sString)
%>
<table width="100%">
<%
If i = 1 Then
idAnt = Sql_Noticia("indice")
%>
<tr>
<td height="160" align="center" bgcolor="#CCCCCC" colspan="3">
<a href="/admin/comum/upload/fotos/<%=Sql_Noticia("Imagem")%>" rel="lightbox" title="<%=titulo%>">
<img src="/admin/comum/upload/fotos/<%=Sql_Noticia("Imagem")%>" width="305" height="160">
</a>
</td>
</tr>
<tr>
<td align="left" height="30" colspan="3">
<a href="/monta.asp?link=exibirNoticia&qual=<%=Sql_Noticia("indice")%>"><font color="#03297E" size="2"><b><%=titulo%></b></font></a>
</td>
</tr>
<tr>
<td height="50" colspan="3">
<a href="/monta.asp?link=exibirNoticia&qual=<%=Sql_Noticia("indice")%>">
<%
If len(titulo) > 40 Then
sTexto = left(rtrim(ltrim(Sql_Noticia("resumo"))),40) & "..."
Else
sTexto = Sql_Noticia("resumo") & "..."
End If
sString = (sTexto)
texto = HTMLEspeciais(sString)
sCont = HTMLDecode(texto)
response.write sCont
%>
</a>
</td>
</tr>
<%
End If
i = i + 1
Sql_Noticia.movenext
Wend
%>
<tr><td height="5"></td></tr>
<tr> set Sql_Noticia = conn.execute("SELECT * FROM noticias WHERE imagem <> '' and indice <> " & idAnt & " ORDER BY indice desc")
j = 0
while not Sql_Noticia.eof And j < 2
sString = Sql_Noticia("titulo")
titulo = HTMLEspeciais(sString) <td width="133" align="center" valign="top">
<table width="100%">
<tr>
<td height="70" align="center" bgcolor="#CCCCCC">
<a href="/admin/comum/upload/fotos/<%=Sql_Noticia("Imagem")%>" rel="lightbox" title="<%=titulo%>">
<img src="/admin/comum/upload/fotos/<%=Sql_Noticia("Imagem")%>" width="133" height="70">
</a>
</td>
</tr>
<tr>
<td align="left" height="30" colspan="3">
<a href="/monta.asp?link=exibirNoticia&qual=<%=Sql_Noticia("indice")%>"><font color="#03297E" size="1"><b><%=titulo%></b></font></a>
</td>
</tr>
<tr>
<td height="30">
<a href="/monta.asp?link=exibirNoticia&qual=<%=Sql_Noticia("indice")%>">sCont = HTMLDecode(texto)
response.write sCont
%>
</a>
</td>
</tr>
</table>
</td>
<td width="28"></td> </tr>
</table> <tr>
<td height="200" align="center"><b><font color="red">Não há dados cadastrados.</font></b></td>
</tr>
<%
End If
Set Sql_Noticia = Nothing
%>
Teria como alguem me ajudar a resolver este probleminha?
Abs
Ah, o código da linha 113, onde diz no site que tem o erro é
set Sql_Noticia = conn.execute("SELECT * FROM noticias WHERE imagem <> '' and indice <> " & idAnt & " ORDER BY indice desc")
Agora deu:
Microsoft JET Database Engine error '80040e07'
Data type mismatch in criteria expression.
/admin/noticias/site/ExibirHome.asp, line 113
Está passando corretamente o valor de idAnt ?
Imprima na tela a query toda para ver o que está sendo executado de fato
Verifique a ortografia. pode ser um nome de coluna Invalido 'sua_coluna'. A coluna a qual você se refere na Base de Dados não foi encontrada. e também veja se os tipos de dados estão corretos
>
Verifique a ortografia. pode ser um nome de coluna Invalido 'sua_coluna'. A coluna a qual você se refere na Base de Dados não foi encontrada. e também veja se os tipos de dados estão corretos
Pois é, fiz isso e agora deu certo!
As noticias estão aparecendo, porem encontrei outro erro, no qual não estou sabendo corrigir:
Vejam: http://www.sociedadealianca.com.br/monta.asp nele é para ter 3 noticias cadastradas, as últimas 3 cadastradas no sistema, porem não estão aparecendo elas, aparece apenas 2, sendo que uma delas repete, como posso corrigir isso?
poste estre trecho do codigo que as lista
qual o numero de erro atual gerado, poste para eu analisar
Então pessoal,
Não da erro, como podem ver no site mesmo: http://www.sociedadealianca.com.br/monta.asp
(São as 3 noticias ali da esquerda)
O problema é que ali deveria aparecer 3 noticias cadastradas no gerenciador de conteudo, porem aparece apenas duas noticias e uma delas repete, sendo que tem 3 diferentes cadastradas no sistema.
O codigo daquela parte ali é:
<!-- #Include Virtual="/admin/comum/includes/conexao.asp"-->
<!-- #Include Virtual="/admin/comum/includes/parametros.asp"-->
<!-- #Include Virtual="/admin/comum/funcoes/asphtml.asp"-->
<%
Function HTMLEspeciais(sString)
If (sString <> "") Then
sString = Replace(sString, "á", "á")
sString = Replace(sString, "â", "â")
sString = Replace(sString, "Ã ", "à")
sString = Replace(sString, "ã", "ã")
sString = Replace(sString, "ç", "ç")
sString = Replace(sString, "é", "é")
sString = Replace(sString, "ê", "ê")
sString = Replace(sString, "Ã", "í")
sString = Replace(sString, "ó", "ó")
sString = Replace(sString, "ô", "ô")
sString = Replace(sString, "õ", "õ")
sString = Replace(sString, "ú", "ú")
sString = Replace(sString, "ü", "ü")
sString = Replace(sString, "Ã", "Á")
sString = Replace(sString, "Â", "Â")
sString = Replace(sString, "À", "À")
sString = Replace(sString, "Ã", "Ã")
sString = Replace(sString, "Ç", "Ç")
sString = Replace(sString, "É", "É")
sString = Replace(sString, "Ê", "Ê")
sString = Replace(sString, "Ã", "Í")
sString = Replace(sString, "Ó", "Ó")
sString = Replace(sString, "Ô", "Ô")
sString = Replace(sString, "Õ", "Õ")
sString = Replace(sString, "Ú", "Ú")
sString = Replace(sString, "Ü", "Ü")
sString = Replace(sString, """", """) '"
sString = Replace(sString, "<", "<") '<
sString = Replace(sString, ">", ">") '>
End If
HTMLEspeciais = sString
End Function
set Sql_Noticia = conn.execute("SELECT * FROM noticias WHERE imagem <> '' ORDER BY indice desc")
If not Sql_Noticia.eof And Not Sql_Noticia.bof Then
set Sql_Ttl = conn.execute("SELECT COUNT(indice) AS Ttl FROM noticias WHERE imagem <> ''")
sTtl = Sql_Ttl("Ttl")
If sTtl = 1 Then
sTtl = 1
ElseIf sTtl = 2 Then
sTtl = 2
Else
sTtl = 3
End If
i = 1
while not Sql_Noticia.eof And i < sTtl
sString = Sql_Noticia("titulo")
titulo = HTMLEspeciais(sString)
%>
<table width="100%">
<%
If i = 1 Then
idAnt = Sql_Noticia("indice")
%>
<tr>
<td height="160" align="center" bgcolor="#CCCCCC" colspan="3">
<a href="/admin/comum/upload/fotos/<%=Sql_Noticia("Imagem")%>" rel="lightbox" title="<%=titulo%>">
<img src="/admin/comum/upload/fotos/<%=Sql_Noticia("Imagem")%>" width="305" height="160">
</a>
</td>
</tr>
<tr>
<td align="left" height="30" colspan="3">
<a href="/monta.asp?link=exibirNoticia&qual=<%=Sql_Noticia("indice")%>"><font color="#03297E" size="2"><b><%=titulo%></b></font></a>
</td>
</tr>
<tr>
<td height="50" colspan="3">
<a href="/monta.asp?link=exibirNoticia&qual=<%=Sql_Noticia("indice")%>">
<%
If len(titulo) > 40 Then
sTexto = left(rtrim(ltrim(Sql_Noticia("resumo"))),40) & "..."
Else
sTexto = Sql_Noticia("resumo") & "..."
End If
sString = (sTexto)
texto = HTMLEspeciais(sString)
sCont = HTMLDecode(texto)
response.write sCont
%>
</a>
</td>
</tr>
<%
End If
i = i + 1
Sql_Noticia.movenext
Wend
%>
<tr><td height="5"></td></tr>
<tr> set Sql_Noticia = conn.execute("SELECT * FROM noticias WHERE imagem <> '' and indice <> " & idAnt & " ORDER BY indice desc")
j = 0
while not Sql_Noticia.eof And j < 2
sString = Sql_Noticia("titulo")
titulo = HTMLEspeciais(sString) <td width="133" align="center" valign="top">
<table width="100%">
<tr>
<td height="70" align="center" bgcolor="#CCCCCC">
<a href="/admin/comum/upload/fotos/<%=Sql_Noticia("Imagem")%>" rel="lightbox" title="<%=titulo%>">
<img src="/admin/comum/upload/fotos/<%=Sql_Noticia("Imagem")%>" width="133" height="70">
</a>
</td>
</tr>
<tr>
<td align="left" height="30" colspan="3">
<a href="/monta.asp?link=exibirNoticia&qual=<%=Sql_Noticia("indice")%>"><font color="#03297E" size="1"><b><%=titulo%></b></font></a>
</td>
</tr>
<tr>
<td height="30">
<a href="/monta.asp?link=exibirNoticia&qual=<%=Sql_Noticia("indice")%>">sCont = HTMLDecode(texto)
response.write sCont
%>
</a>
</td>
</tr>
</table>
</td>
<td width="28"></td> </tr>
</table> <tr>
<td height="200" align="center"><b><font color="red">Não há dados cadastrados.</font></b></td>
</tr>
<%
End If
Set Sql_Noticia = Nothing
%>EU acessei o site e etsva 3 noticias diferente,
mas da um response.write na sua string SQL para ver o que esta seno passado
Não entendi direito a mecanica deste trecho (a gripe impedindo o cerebro de agir) :
set Sql_Noticia = conn.execute("SELECT * FROM noticias WHERE imagem <> '' ORDER BY indice desc")
If not Sql_Noticia.eof And Not Sql_Noticia.bof Then
set Sql_Ttl = conn.execute("SELECT COUNT(indice) AS Ttl FROM noticias WHERE imagem <> ''")
sTtl = Sql_Ttl("Ttl")
If sTtl = 1 Then
sTtl = 1
ElseIf sTtl = 2 Then
sTtl = 2
Else
sTtl = 3
End If
i = 1
while not Sql_Noticia.eof And i < sTtl
sString = Sql_Noticia("titulo")
Não seria mais simples fazer um select Top ou com Limit dependendo do banco de dados que está usando ?
selet * from tabela where algo=algumacoisa limit 0,3
Por exemplo ?
>
Não entendi direito a mecanica deste trecho (a gripe impedindo o cerebro de agir) :
set Sql_Noticia = conn.execute("SELECT * FROM noticias WHERE imagem <> '' ORDER BY indice desc")
If not Sql_Noticia.eof And Not Sql_Noticia.bof Then
set Sql_Ttl = conn.execute("SELECT COUNT(indice) AS Ttl FROM noticias WHERE imagem <> ''")
sTtl = Sql_Ttl("Ttl")
If sTtl = 1 Then
sTtl = 1
ElseIf sTtl = 2 Then
sTtl = 2
Else
sTtl = 3
End If
i = 1
while not Sql_Noticia.eof And i < sTtl
sString = Sql_Noticia("titulo")
Não seria mais simples fazer um select Top ou com Limit dependendo do banco de dados que está usando ?
selet * from tabela where algo=algumacoisa limit 0,3
Por exemplo ?
Banco de dados que estou usando é o Access!
Desculpe minha ignorancia, mas nao entendo praticamente nada de programação.
Eu deveria então substituir o código que você citou, por apenas essa linha que você passou?
Abrass
Para access seria
SELECT TOP 3 * FROM tabela
Se o que postei funcionar, daria para eliminar algumas linhas de codigo desnecessárias do seu script.
Como não manja nada de programação, seria melhor procurar alguma apostila de asp para ter alguma noção, pois assim, agilizará o entendimento.
>
Para access seria
SELECT TOP 3 * FROM tabela
Se o que postei funcionar, daria para eliminar algumas linhas de codigo desnecessárias do seu script.
Como não manja nada de programação, seria melhor procurar alguma apostila de asp para ter alguma noção, pois assim, agilizará o entendimento.
Tentei este codigo que vocÊ citou Vinicius, mas não funcionou!
Vou ver se acho algum programador para resolver isso para mim o quanto antes, pois o cliente ja está me precionando para resolver isso e colocar o site no ar.
Obrigado!
dá um response.write ma sua string SQL para ver o que esta sendo passada
coloca aspas simples no " & idAnt & " e testa novamente!