Amigos estoy en un problema. soy programador en php. y me han pedido urgente un sistema en asp. con oracle. Necesito a traves de un form con subit, generar una consulta a la base. para luego desplegarla. tengo solo la query.
muchas gracias
| |||
| de php a asp Amigos estoy en un problema. soy programador en php. y me han pedido urgente un sistema en asp. con oracle. Necesito a traves de un form con subit, generar una consulta a la base. para luego desplegarla. tengo solo la query. muchas gracias |
| |||
| Espero que esto te sirva (a grosso modo)
Código:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Dim cnn,sSQL,oRS
if request.Form("submit") <> "" then
set cnn = server.CreateObject("ADODB.Connection")
set oRS = server.CreateObject("ADODB.Recordset")
' Para la cadena de conexion busca en http://www.connectionstrings.com/
' O esta cadena de conexion
strConnect ="Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd;"
' o esta
strConnect ="Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;"
on error resume next
cnn.Open strConnect
if err.number<>0 then
response.Write(err.description)
elseif cnn.State = 2 then
response.Write("No hay conexion con la base de datos. Por favor, intentelo mas tarde.")
else
on error goto 0
end if
' Formas el SQL con lo que venga en
sSQL = "SELECT * FROM tabla WHERE campo LIKE '%" & request.Form("texto") & "%'"
set oRS = cnn.execute(sSQL)
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Documento sin título</title>
</head>
<body>
<%
' Aqui va el listado, el interface te lo dejo para ti :-)
if isObject(oRs) then
do while not oRs.EOF
' Como puedes ver, esto es lo mismo que el fetch_array de PHP
response.Write(oRs("campo1")
' No se te olvide esto pues puedes provocar un bucle sin fin
oRs.movenext
loop
else
%>
<form action="" method="post" name="foirm1" id="foirm1">
<input type="text" name="texto">
<input type="submit" name="submit" value="Buscar">
</form>
<%
end if
%>
</body>
</html>
<%
if isObject(oRs) then
if oRs.State <> 0 then oRs.close()
set oRs = nothing
end if
if isObject(cnn) then
if cnn.State <> 0 then cnn.close()
set cnn = nothing
end if
%>
Un saludo Última edición por tammander; 10/02/2006 a las 06:46 |
| |||
| hice el formulario, con su correspondiente submit. <form action=index.asp method = post name =formu> <text> <text> <input type submit> </form> pero mi estrucura es asi: if request.Form("submit") <> "" then haga la consulta... response.write"antro al submit" else haga el formulario end if al submitar no entra al if.. que sera??? atte mauricio pero fijate que al |
| |||
| no me funciona el if request.Form("submit") = "enviar" then if request.Form("submit") <> "" then no entra!! en php seria algo asi: if($_POST) primero le digo si viene de submit, ejecute la consulta, sino que muestre la pantalla de ingreso Viejo grande tu ayuda!! muchas gracias |
| |||
| <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <% Dim cnn,sSQL,oRS response.Write" entrando al sistema " if request.Form("submit") <> "" then 'if Request.Form() <> "" then %> <!-- #include file="include/asp/connect.inc"--> <!-- #include file="include/asp/getDescrip.inc"--> <!-- #include file="include/asp/ejecutaQuery.inc"--> <% f_inicio = request( "f_inicio") f_final = request( "f_final" ) matricula = request("matricula") response.Write"matricula" sql= "select matricula " & _ ",decode (ident_pc, 4112, '1.1',4144,'1.3' " & _ ",8208,'2.1'" & _ ",8224,'2.2'" & _ ",12304,'3.1'" & _ ",12320,'3.2'" & _ ",12336,'3.3'" & _ ",12352,'3.4'" & _ ",16400,'4.1'" & _ ",16416,'4.2'" & _ ",16432,'4.3'" & _ ",20496,'5.1'" & _ ",20512,'5.2'" & _ ",20528,'5.3'" & _ ",20544,'5.4') PdC" & _ ", to_char(fechatransito,'dd-mm-yyyy') Fecha" & _ ", to_char(fechatransito,'hh24:mi') Hora" & _ ", importe" & _ ", decode (tarifamop,1,'Fuera Punta'" & _ ",2,'Punta') Tarifa " & _ ", decode (categoria,1,'Auto/Camioneta'" & _ ",2,'Camion s/Acoplado'" & _ ",3,'Camion c/Acoplado') Categoria " & _ "from TRANSACCIONES_OLAP_MV" & _ "where (fechatransito between to_date('f_inicio','dd-mm-yyyy hh24:mi:ss')" & _ "and to_date('f_final','dd-mm-yyyy hh24:mi:ss'))" & _ "and trim(matricula) in ('matricula') " & _ "order by matricula" do while getRegistro( conn, rec, sql )%> <tr bgcolor="#FFFFFF"> <td class=textoEstandar> </td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_diezminutos"),2)%></td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_concesion"),2)%></td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_dia"),2)%></td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_mes"),2)%></td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_ano"),2)%></td> </tr><% loop else %> <html> <!-- #include file="include/asp/head.asp"--> <body> <!-- #include file="include/asp/menu.asp"--> <table border=0 cellspacing=0 cellpadding=0 style="width:760px"> <tr> <td align=center><br> <form action ="index.asp" name="frmingreso" method=post onSubmit="return validacampos()"> <div style="width:60%;height:26"> <table border="1" width="100%"> <tr> <td ><font class=textoEstandarSizeBold>Fecha de Inicio</font></td> <td width="211"> <INPUT type ="text" name="f_inicio" size="15" class=inputEstandar> </td> </tr> <tr> <td><b><font class=textoEstandarSizeBold>Fecha Final</font></td> <td width="211"> <INPUT type ="text" name="f_final" size="15" class=inputEstandar> </td> </tr> <tr> <td><b><font class=textoEstandarSizeBold>Matrícula</font></td> <td width="211"> <INPUT type ="text" name="matricula" size="15" class=inputEstandar> </td> </tr> </table> <p><font class=textoEstandarSizeRed>Ingreso los datos requeridos</font> <table border="1" width="100%"> <tr> <td align="center"><input type=submit class=botonEstandar value="Consultar" name="enviar" ></td> </tr> </table> <p> </div> </form> </td> </tr> </table> <% end if %> Sres no me funcina! probe los tres metodos que me recomendaron. y no pasa nada!. Uff. Les agradesco la ayuda!! |
| |||
| esto lo hago siempre en php. la idea es recargar la misma pagina. y la forma es poner en el action el nombre de la misma pagina (por ejemplo, hay otros) tonces asi poner if request.form("submit")<>"" then haga la consulta con los oparametros ingresados else muestre la pagina de ingreso end if |
| |||
| Pues es raro. ¿Has probado el tercer metodo que te puse antes? el que lee las variables del sistema. De todas formas el loop no se si te lo hará. ![]() Otra cosa: Ese loop esta por encima del tag HTML. Deberia ir en una tabla en el body. Tambien te recomiendo que toquetees los header para que no se guarde en caché (talmente como PHP): Response.Expires = -1 Response.ExpiresAbsolute = Now() - 2 Response.AddHeader "pragma","no-cache" Response.AddHeader "cache-control","private" Response.CacheControl = "No-Store" Un saludo |
| |||
| estas seguro se que if instr(request.ServerVariables("CONTENT_TYPE"),"app lication/x-www-form-urlencoded") then no le falta o le sobra algo?? lo curioso es que en asp la pagina solo no carga ni siquira me manda un warnning... Atte Mauricio |
| |||
| entro!!! con este if... enviar es el name del btn submit. pero "supongo" que algo anda mal en este codigo por que al submitar me manda un No se puede mostrar la página !! If Request.Form("enviar")<>"" Then %> <!-- #include file="include/asp/connect.inc"--> <!-- #include file="include/asp/getDescrip.inc"--> <!-- #include file="include/asp/ejecutaQuery.inc"--> <% f_inicio = request( "f_inicio") f_final = request( "f_final" ) matricula = request("matricula") response.Write"matricula" sql= "select matricula " & _ ",decode (ident_pc, 4112, '1.1',4144,'1.3' " & _ ",8208,'2.1'" & _ ",8224,'2.2'" & _ ",12304,'3.1'" & _ ",12320,'3.2'" & _ ",12336,'3.3'" & _ ",12352,'3.4'" & _ ",16400,'4.1'" & _ ",16416,'4.2'" & _ ",16432,'4.3'" & _ ",20496,'5.1'" & _ ",20512,'5.2'" & _ ",20528,'5.3'" & _ ",20544,'5.4') PdC" & _ ", to_char(fechatransito,'dd-mm-yyyy') Fecha" & _ ", to_char(fechatransito,'hh24:mi') Hora" & _ ", importe" & _ ", decode (tarifamop,1,'Fuera Punta'" & _ ",2,'Punta') Tarifa " & _ ", decode (categoria,1,'Auto/Camioneta'" & _ ",2,'Camion s/Acoplado'" & _ ",3,'Camion c/Acoplado') Categoria " & _ "from TRANSACCIONES_OLAP_MV" & _ "where (fechatransito between to_date('f_inicio','dd-mm-yyyy hh24:mi:ss')" & _ "and to_date('f_final','dd-mm-yyyy hh24:mi:ss'))" & _ "and trim(matricula) in ('matricula') " & _ "order by matricula" do while getRegistro( conn, rec, sql )%> <tr bgcolor="#FFFFFF"> <td class=textoEstandar> </td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_diezminutos"),2)%></td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_concesion"),2)%></td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_dia"),2)%></td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_mes"),2)%></td> <td align=right class=textoEstandar><%=FormatNumber(rec("porcentaj e_ano"),2)%></td> </tr><% loop graaaacias!! |
| |||
| No, no le falta nada. instr es similar a stristr. Veamos si me aclaro: 1 - Pasa la funcion javascript de validacion del formulario y se reenvia a si mismo (por cierto, request.ServerVariables("SCRIPT_NAME") es lo mismo que $_SERVER["PHP_SELF"] ) Hasta aqui bien? Por cierto, que hace getRegistro? Un saludo |
| |||
| me fue bien con el submit, tenia otro problema fuera de el, y por eso al submitar encontraba el error no mostrando nada. pero necesito otra ayudita: ESta es mi conexion por odbc... Set conn = Server.CreateObject("ADODB.Connection") conn.Open "DSN=CopProvisorio;UID=olap;PWD=olap" conn.CursorLocation = 3 'adUseClient que difiere del ejemplo de mas arriba en strConnect ="Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd;" tonces como ejecuto mi query segun mi coneccion?? Atte mauricio Pd. Gracias por responder!! |
| |||
| Nada, nada. Para eso estamos Aunque me resulta curioso que alguien se pase de PHP a ASP. Esos arrays asociativos (como los echo de menos en ASP), esa forma de trabajar con archivos, esa... en fin, no hay color. Aunque hay que reconocer que con ASP se trabaja mucho mas rápido y es mucho mas intuitivo.Lo dicho, a mandar Un saludo |