Jump to content


Photo

O Que Há De Errado....


  • Faça o login para participar
3 replies to this topic

#1 AsmuL

AsmuL

    12 Horas

  • Usuários
  • 147 posts
  • Sexo:Não informado
  • Localidade:SG / RJ
  • Interesses:Mulher, Dinheiro, Programar

Posted 19/10/2004, 13:34

<%@Language="VBSCRIPT"%>
<%

Dim qrySQL

qrySQL = "INSERT INTO TESTE_TBL (NOME,EMAIL) VALUES ('RAFAEL', 'RAFAELSRAMOS@YAHOO.COM.BR');"
	
	function ExecQry (pQry)

  Dim ObjConn
	
  Set ObjConn = Server.CreateObject("ADODB.Connection")
  ObjConn.Open "dbTeste"
	
  ObjConn.Execute pQry
	
	end function

if ExecQry(qrySQL) then

	response.write("Query executada com sucesso")
	
else
  
	response.write("Query não executada")
	
end if

%>

O que há de errado aí galera... ?

tá caindo sempre no else, porém ele insere no banco !


vlw !
[ PHP | ASP | VB | Delphi | MySQL | Access | Interbase | MSSQL | ORACLE ]

#2 powerAsp_X

powerAsp_X
  • Visitantes

Posted 19/10/2004, 13:57

Amigo antes de responder vamos entender uma coisa antes.

Analise comigo o fragmento do seu código:

if ExecQry(qrySQL) then
  response.write("Query executada com sucesso")
else
  response.write("Query não executada")
end if

No código acima, voce verifica o retorno da funcao ExecQry. Porém este retorno não existe, pois vc nao o criou.

Sempre que utilizar funções, estas devem retornar algum valor.

Quando for apenas para executar um código, utilize Procedimentos.

Altere a sua função por esta:


function ExecQry (pQry)
 
 On Error Resume Next

 Dim ObjConn, blnRetorno

 blnRetorno = False

 Set ObjConn = Server.CreateObject("ADODB.Connection")
 ObjConn.Open "dbTeste"
 ObjConn.Execute pQry
 
 If err.Number = 0 Then 
   blnRetorno = True
 Else
  blnRetorno = False
 End if

 ExecQry = blnRetorno
end function

Agora vai funcionar.

[]'s

:ph34r:

Edição feita por: powerAsp_X, 19/10/2004, 14:03.


#3 AsmuL

AsmuL

    12 Horas

  • Usuários
  • 147 posts
  • Sexo:Não informado
  • Localidade:SG / RJ
  • Interesses:Mulher, Dinheiro, Programar

Posted 19/10/2004, 14:05

Valeu cara.. sou iniciante em ASP.

Programo em PHP.

ah ! fiz uma alteração na função pq continuou sem funcionar !

function ExecQry (pQry)
   
   On Error Resume Next

   Dim ObjConn, blnRetorno

   blnRetorno = False

   Set ObjConn = Server.CreateObject("ADODB.Connection")
   ObjConn.Open "dbTeste"

   ObjConn.Execute pQry

   if err.Number = 0 then 
      blnRetorno = True
   end if

   ExecQry = blnRetorno

end function

%>


agora tá na moral !
vlw !
abraço !
[ PHP | ASP | VB | Delphi | MySQL | Access | Interbase | MSSQL | ORACLE ]

#4 powerAsp_X

powerAsp_X
  • Visitantes

Posted 19/10/2004, 14:08

Abraços meu...

Qqr coisa dá o toque.

:ph34r:




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq