Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Galera, eu tenho o seguinte código abaixo, que eu preciso fazer consulta em duas tabelas: "contratos" e "cad_cheque". E está dando o seguinte erro:
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'cod_contrato='.
/controle/entrada_cheques.asp, line 87
Segue o código:
<!--#include file="conexao.asp"-->
<!--#INCLUDE FILE = "config.inc" -->
<%
dim sessao
sessao = Request.QueryString("sessao")
Session("sessao") = sessao
strsql1="select * from usuario where codigo=" & Session("cod_usuario")
set rs1=Conn.execute(strsql1)
%>
<HTML>
<link href="estilo.css" rel="stylesheet" type="text/css" />
<STYLE type=text/css>
@import url("style.css");
</STYLE>
<style type="text/css">
<!--
body {
background-image: url(../base_rsvp/images/fundo_pagina.gif);
background-repeat: repeat;
}
-->
</style><style type="text/css">
<!--
body,td,th {
font-size: 9px;
}
-->
</style><HEAD>
<TITLE>Contratos Fechados</TITLE>
</script>
<style media="print">
.oculta
{
visibility: hidden
}
</style>
</script>
<%
Session.LCID = 1046
Session.TimeOut = 600
%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</HEAD>
<BODY>
<div align="center">
<div align="center"><img src="../base_rsvp/images/banner_painel.jpg" width="754" height="100">
<br />
<br>
<!--#INCLUDE FILE = "menu_drop.asp" -->
<br>
</div>
<table width="755" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="614" align="center" valign="top"><table width="754" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#666666" bgcolor="#663333">
<tr>
<td colspan="6" class="style4"><div align="center">..:: Controle de Cheques ::..</div></td>
</tr>
<tr>
<td width="42" height="16" class="style4"><div align="center">Cod.</div></td>
<td width="82" class="style4"><div align="center">Nº Cheque</div></td>
<td width="321" class="style4"><div align="center">Nome</div></td>
<td width="96" class="style4"><div align="center">Valor</div></td>
<td width="96" class="style4"><div align="center">Vencimento</div></td>
<td width="103" class="style4"><div align="center">Editar</div></td>
</tr>
</table>
<br>
<%Const TamanhoPagina = 20
set rsQuery = Server.CreateObject( "ADODB.RecordSet" )
rsQuery.PageSize = TamanhoPagina
rsQuery.CacheSize = TamanhoPagina
rsQuery.CursorType = 3
'rsQuery.Open"select * from cad_cheque order by cod_cheque desc", Conn
rsQuery.Open "select * from cad_cheque where cod_contrato="& cod2 &" order by vencimento", Conn
response.write(strsql2)
responde.end
if Session("PaginaAtual") = "" then Session("PaginaAtual") = 1
select case Request.QueryString( "modo" )
case "proxima"
Session("PaginaAtual") = min( Session("PaginaAtual") + 1, rsQuery.PageCount )
case "anterior"
Session("PaginaAtual") = max( Session("PaginaAtual") - 1, 1 )
case "pagina"
if isNumeric( request.QueryString("numero") ) then
Session("PaginaAtual") = cint( request.QueryString("numero") )
Session("PaginaAtual") = max( min( Session("PaginaAtual"), rsQuery.PageCount ), 1 )
end if
end select
rsQuery.AbsolutePage = Session("PaginaAtual")
cod_cheque=rsQuery("cod_cheque")
%>
<%
while not rs2.eof
cod2=rs2("cod_contrato")
%>
<%
rs2.movenext
wend
%>
<table width="754" border="1" align="center" cellpadding="1" cellspacing="0" bordercolor="#666666" bordercolorlight="<%= mainborderlight%>" bordercolordark="<%= mainborderdark%>">
<tr bordercolor="000000">
<%
item = 1
do while item <= TamanhoPagina and not rsQuery.eof
cod_cheque=rsQuery("cod_cheque") <td width="33" bordercolor="#666666" bgcolor="#663333" class="style4"><div align="center"><%=rsQuery("cod_cheque")%></div></td>
<td width="63" height="10" bordercolor="#666666" bgcolor="#663333" class="style4"><div align="center"><%=rsQuery("numero_cheque")%></div></td>
<td width="255" bordercolor="#666666" bgcolor="#663333" class="style4"> <%=rsQuery("contratante")%></td>
<td width="75" bordercolor="#666666" bgcolor="#663333" class="style4"><div align="right"><%=rsQuery("valor")%> </div></td>
<td width="75" bordercolor="#666666" bgcolor="#663333" class="style4"><div align="center"><%=rsQuery("vencimento")%></div></td>
<td width="27" bordercolor="#666666">
<div align="center"><a href="ver_cheque.asp?cod_cheque=<%=cod_cheque%>"><img src="../images/ico_visualizar.gif" title="visualizar cheque" alt="visualizar cheque" width="25" height="25" border="0"></a></div>
<div align="center"></div></td>
<td width="18">
<div align="center"><a href="imprimir_cheque.asp?cod_cheque=<%=cod_cheque%>" target="_blank"><img src="../images/ico_imprimir.gif" title="imprimir cheque" alt="imprimir cheque" width="25" height="24" border="0"></a> </div></td>
<td width="25" bordercolor="#999999">
<div align="center"><a href="visualizar_excluir_cheque.asp?cod_cheque=<%=cod_cheque%>"><img src="../images/ico_excluir.gif" title="excluir cheque" alt="excluir cheque" width="25" height="24" border="0"></a> </div></td>
<% rsQuery.Movenext
item = item + 1
n = n + 1
loop %>
<% next %>
</tr>
<% loop %>
</table>
<br>
<span class="style8">Há</span> <span class="style13"><%= rsQuery.RecordCount %></span> <span class="style8">cheques:</span> <br>
<span class="style8">Você está na página</span> <span class="style13"><%= Session("PaginaAtual") %></span>
<span class="style8">de</span> <span class="style13"><%= rsQuery.PageCount %></span><br>
<span class="style8">Ir para página:</span>
<span class="style13">
<%
if Session("PaginaAtual") > 1 then 'Colocar o link para página anterior se não for a primeira
response.write "<a href=""entrada_cheques.asp?cod="& cod &"&modo=anterior"">Anterior</a> "
end if
for n = 1 to rsQuery.pageCount
if n = Session("PaginaAtual") then
response.write n & " " ' Se for a página atual, não colocar link, só o número dela.
else
response.write "<a href=""entrada_cheques.asp?cod="& cod &"&modo=pagina&numero=" & n & """>" & n & "</a> "
end ifif Session("PaginaAtual") < rsQuery.pageCount then 'Colocar o link para próxima página se não for a última
response.write "<a href=""entrada_cheques.asp?cod="& cod &"&modo=proxima"">Próxima</a> "
end if
%>
</span></td>
</tr>
</table>
<div align="center"></div>
</body>
</html>function min( value1, value2 )
min = iif( value1 < value2, value1, value2 )
end function
function max( value1, value2 )
max = iif( value1 > value2, value1, value2 )
end function
%>
Essa é a linha 87: "rsQuery.Open "select * from cad_cheque where cod_contrato="& cod2 &" order by vencimento", Conn "
Alguém pode me ajudar !!
dá um response.write na sua string SQL para ver o que esta sendo passaso de valor
SQL=""select * from cad_cheque order by cod_cheque desc"
response.write SQL
response.end()
você diz pra eu dar um response.write, acima do código é isso ?
Eu coloquei como está abaixo é isso mesmo ?
Se for deu erro na linha: "while not rs2.eof"
response.write(strsql2)
responde.end
<%
while not rs2.eof
cod2=rs2("cod_contrato")
%>
<%
rs2.movenext
wend
%>
O erro foi o seguinte:
>
response.write(strsql2) responde.end
Microsoft VBScript runtime error '800a01a8'
Object required: ''
/controle/entrada_cheques.asp, line 109
faz assim:
SQL=""select * from cad_cheque order by cod_cheque desc"
response.write SQL
response.end()
Apareceu o seguinte erro:
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
/controle/entrada_cheques.asp, line 101
Essa é a linha 101:
rsQuery.AbsolutePage = Session("PaginaAtual")cod_cheque=rsQuery("cod_cheque")
Em versões mais antigas do MDAC, o erro pode ser essa mensagem
Operation is not allowed when the object is closed.
Esse erro pode ser causado quando você tenta acessar os valores de um conjunto de registros vazio ou um conjunto de registros que já tenha sido fechado. A causa mais comum, no entanto, parece resultar de chamar uma stored procedure que não usa SET NOCOUNT.
Erro na linha 85: "[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'cod_contrato='."
Essa é a linha:
rsQuery.Open "select * from cad_cheque where cod_contrato="& cod2 &" order by vencimento", Conn
coloque assim:
cod_contrato='"& cod2 &"'
e volto a perguntar, vem algum valor nessa variavel? já testou?
qual é o tipo de campo para a variavel cod2 ?
Resolvido, segue o código:
<!--#include file="conexao.asp"-->
<%
dim sessao
sessao = Request.QueryString("sessao")
Session("sessao") = sessao
strsql1="select * from usuario where codigo=" & Session("cod_usuario")
set rs1=Conn.execute(strsql1)
%>
<HTML>
<link href="estilo.css" rel="stylesheet" type="text/css" />
<STYLE type=text/css>
@import url("style.css");
</STYLE>
<style type="text/css">
<!--
body {
background-image: url(../base_rsvp/images/fundo_pagina.gif);
background-repeat: repeat;
}
-->
</style><style type="text/css">
<!--
body,td,th {
font-size: 9px;
}
-->
</style><HEAD>
<TITLE>Contratos Fechados</TITLE>
</script>
<style media="print">
.oculta
{
visibility: hidden
}
</style>
</script>
<%
Session.LCID = 1046
Session.TimeOut = 600
%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</HEAD>
<BODY>
<div align="center">
<div align="center"><img src="../base_rsvp/images/banner_painel.jpg" width="754" height="100">
<br />
<br>
<!--#INCLUDE FILE = "menu_drop.asp" -->
<br>
</div>
<table width="755" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="614" align="center" valign="top"><table width="754" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#666666" bgcolor="#663333">
<tr>
<td width="754" colspan="6" bgcolor="#142E61" class="style4"><div align="center" class="style2">..:: Resultado da Consulta ::..</div></td>
</tr>
<tr>
<td colspan="6" bgcolor="#142E61" class="style4"> </td>
</tr>
</table>
<br>
<br>
<table width="754" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="12" height="60" bgcolor="#0E2E61"> </td>
<td width="971" align="center" bgcolor="#FFFFFF"><br />
<%
query_busca = request.querystring("palavra")
pg = HTTP_REFERER 'pega o nome completo da página
Set rsQuery = Server.CreateObject("adodb.recordset")
rsQuery.CursorLocation = 3
rsQuery.CursorType = 0
rsQuery.LockType = 1
rsQuery.Open"select * from contratos where noiva like '%"& query_busca &"%'", Conn
Const NumPorPage = 10 'Numero de registros por página
colNum=1
if rsQuery.eof then
%>
<span class="style4">Nenhum resultado com a Palavra</span> <span class="b"><%=query_busca%></span>
<%
else
Dim PagAtual
IF Request.QueryString("PagAtual") = "" Then
PagAtual = 1 'Primeira página
Else
PagAtual = Request.QueryString("PagAtual")
End If
rsQuery.CacheSize = NumPorPage 'Define o tamanho do Cache = para o número de registros
rsQuery.MoveFirst 'Move o RecorSet para o início '
rsQuery.PageSize = NumPorPage 'Coloca a quantidade de páginas
Dim TotalPages 'Pega o número total de página
TotalPages = rsQuery.PageCount
rsQuery.AbsolutePage = PagAtual 'Configura a página atual
Count = 0 'Zera o contador
DO WHILE NOT rsQuery.EOF And Count < rsQuery.PageSize
%>
</span>
<table width="99%" border="1" align="center" cellpadding="1" cellspacing="0">
<tr bordercolor="000000">
<%
For n = 0 To limite
%>
<%
Dim n
n = 0
do while n < colNum and NOT rsQuery.eof
%>
<td height="25" colspan="3" valign="top"><div align="center" class="style1">
<div align="left" class="style1">
<table width="100%" border="0" cellspacing="0">
<tr>
<td width="5%" bgcolor="#CCCCCC"><div align="center" class="style4"><%=rsQuery("cod_contrato")%> </div></td>
<td width="7%" bgcolor="#CCCCCC"><div align="center"><span class="style4"><%=rsQuery("numero_contrato")%> </span></div></td>
<td width="45%" bgcolor="#CCCCCC"><div align="left"><span class="style3"><span class="style4"> <%=rsQuery("noiva")%> + <%=rsQuery("noivo")%></span></span></div></td>
<td width="14%" bgcolor="#CCCCCC"><div align="center"><span class="style4"><%=rsQuery("data")%></span></div></td>
<td width="19%" bgcolor="#CCCCCC"> </td>
<td width="5%" align="center" bgcolor="#CCCCCC"><a href="ver_contrato.asp?cod_contrato=<%=cod_contrato%>"><img src="../images/ico_visualizar.gif" title="visualizar contrato" alt="visualizar contrato" width="25" height="24" border="0" /></td>
<td width="5%" align="center" bgcolor="#CCCCCC"><a href="visualizar_excluir_contrato.asp?cod_contrato=<%=cod_contrato%>"><img src="../images/ico_excluir.gif" title="excluir contrato" alt="excluir contrato" width="25" height="24" border="0" /></td>
</tr>
</table>
</div>
</div></td>
<%
Count = Count + 1
n = n + 1
rsQuery.MoveNext
loop
%>
<% next %>
</tr>
<% loop %>
</table>
<br>
<div align="center" class="nomelink"> <span class="busca4"><br>
<br>
</span><span class="style4">Há</span><span class="style14">
<%= rsQuery.RecordCount
%></span><span class="style4"> Cadastro(s)</span><br>
<span class="style4">
<%
Response.Write("<span class='busca4'>Página " & PagAtual & " de " & TotalPages & "<br></span>")
IF PagAtual > 1 THEN
Response.Write("<a href='"& pg &"?palavra=" & query_busca &"&PagAtual=" & 1 & "' class='nomelink'>")
Response.Write("Primeira")
Response.Write(" ")
Response.Write("<a href='"& pg &"?palavra=" & query_busca &"&PagAtual=" & PagAtual - 1 & "' class='nomelink'>")
Response.Write("<<")
Response.Write(" ")
Else
Response.Write("Primeira")
Response.Write(" ")
Response.Write("<<")
Response.Write(" ")
End If
max_n_mostrados = 10
intervalo = Int(max_n_mostrados /2)
inicio = PagAtual - intervalo
final = PagAtual + intervalo
If CInt(inicio) <1 Then
inicio = 1
final = max_n_mostrados
END IF
If CInt(final) > CInt(TotalPages) Then final = TotalPages
For i = inicio To final
If CInt(i)=CInt(PagAtual) Then
Response.Write "<font class='b'>[ <B>" & i & "</B>]</font> "
END IF
If CInt(i) < CInt(PagAtual) Then
Response.Write "<a href='"& pg &"?palavra="&query_busca&"&PagAtual=" & i & "' class='nomelink'>" & i & "</a> "
END IF
If CInt(i) > CInt(PagAtual) Then
Response.Write "<a href='"& pg &"?palavra="&query_busca&"&PagAtual=" & i & "' class='nomelink'>" & i & "</a> "
END IF
Next
IF CInt(PagAtual) <> CInt(TotalPages) THEN
'Se estiver na Última página, mostra apenas o botão Anterior e Primeira
Response.Write("<a href='"& pg &"?palavra=" & query_busca &"&PagAtual=" & PagAtual + 1 & "' class='nomelink'>")
Response.Write(">>")
Response.Write(" ")
Response.Write("<a href='"& pg &"?palavra=" & query_busca &"&PagAtual=" & TotalPages & "' class='nomelink'>")
Response.Write("Ultima")
Else
Response.Write(" ")
Response.Write(">>")
Response.Write(" ")
Response.Write("Ultima")
End If %>
<br>
<br>
</span></div>
<span class="style4">
<% end if %>
</span></td>
<td width="13" bgcolor="#0E2E61"></td>
</tr>
</table></td>
</tr>
</table>
<div align="center"></div>
</body>
</html>function min( value1, value2 )
min = iif( value1 < value2, value1, value2 )
end function
function max( value1, value2 )
max = iif( value1 > value2, value1, value2 )
end function
%>
parece que a variável "cod2" está vindo vazia, imprima ela antes para ver se está vindo algo valor!