Foros del Web » Programando para Internet » ASP Clásico »

Select Sql Y Select En Excel..

Estas en el tema de Select Sql Y Select En Excel.. en el foro de ASP Clásico en Foros del Web. Ojala alguien pueda ayudarme con lo siguiente: Tengo este codigo con el cual consigo conectarme a una tabla excel y leer los datos que existen ...
  #1 (permalink)  
Antiguo 02/04/2007, 08:03
 
Fecha de Ingreso: abril-2001
Mensajes: 46
Antigüedad: 23 años, 1 mes
Puntos: 0
Select Sql Y Select En Excel..

Ojala alguien pueda ayudarme con lo siguiente:
Tengo este codigo con el cual consigo conectarme a una tabla excel y leer los datos que existen en ella:

<html>
<head>
<title>Consultar Hoja Excel</title>
</head>

<%mifol=request("fol") CAMPO OBTENIDO DE UN FORMULARIO
Path=Server.MapPath("Ejercicio1.xls")
Set ConexionBD = Server.CreateObject("ADODB.Connection")
ConexionBD.Open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" & Path
Set rs = Server.CreateObject("ADODB.Recordset")


rs.open"select * from feriado order by Nombre, Folio, Imagen", ConexionBD,3,3
%>

<body>
<h2><b><center>VISTA DE IMAGENES</center></b></h2>
<hr>
<table border=1 align="center">

<%

columnas = rs.Fields.Count
rs.MoveFirst
Do While Not rs.EOF
Response.write ("<img src="& rs.Fields.Item(2).Value &">")
rs.MoveNext
Loop
Response.Write "</table>"

rs.Close
Set rs = Nothing
ConexionBD.Close
Set ConexionBD = Nothing
%>
</body>
</html>


AHORA: LO QUE NECESITO ES
CON EL CODIGO ANTERIOR OBTUVE UNA SELECT PERO DE TODA LA BASE, Y SOLO NECESITO LOS DATOS QUE CUMPLEN CIERTA CONDICION POR EJEMPLO: QUE MUESTRE LA IMAGEN DE ACUERDO A UN NUMERO DE FOLIO DETERMINADO EL QUE FUE INGRESADO EN UN FORMULARIO ANTERIORMENTE Y NO CONSIGO HACERLO, PREGUNTO COMO LO HARIA NORMALMENTE EN UNA SELECT SQL PERO ME MARCA ERROR. ALGUNA SUGERENCIA¿?

DE ANTEMANO MUCHISIMAS GRACIAS POR LA AYUDA
__________________
Alice
  #2 (permalink)  
Antiguo 02/04/2007, 15:03
 
Fecha de Ingreso: junio-2006
Mensajes: 109
Antigüedad: 18 años
Puntos: 2
Re: Select Sql Y Select En Excel..

Serian varias cosas:

1) La variable que utilizas "mifol" ingresala como parte del select que estas haciendo:

Código:
rs.open"select * from feriado where Folio = CASE WHEN "&mifol&" = '' THEN Folio ELSE "&mifol&" END order by Nombre, Folio, Imagen", ConexionBD,3,3
2) En la parte donde recorres y preguntas por el número de columnas valida mejor el recordset, agregando una validación más:

Código:
IF IsOpenRecordSet(rs) THEN
  With rs		 
    IF (Not .BOF And Not .EOF) THEN
    END IF
  END with
END IF
La función seria algo asi:
Código:
Function IsOpenRecordSet(objRS)
    If IsNull(objRS) Or objRS Is Nothing Then
        IsOpenRecordSet = False
        Exit Function
    End If

'objRS.State = 0 Indicates that the object is closed. 
'objRS.State = 1 Indicates that the object is open. 
'objRS.State = 2 Indicates that the object is connecting. 
'objRS.State = 4 Indicates that the object is executing a command. 
'objRS.State = 8 Indicates that the rows of the object are being 
    If IsObject(objRS) Then
        If objRS.State = 1 Then
            IsOpenRecordSet = True
        Else
            IsOpenRecordSet = False
        End If
    Else
        IsOpenRecordSet = False
    End If
End Function
Suerte
  #3 (permalink)  
Antiguo 02/04/2007, 22:58
Avatar de Mithrandir
Colaborador
 
Fecha de Ingreso: abril-2003
Mensajes: 12.106
Antigüedad: 21 años, 1 mes
Puntos: 25
Re: Select Sql Y Select En Excel..

Poco que ver con SQL Server. Movido a ASP.
__________________
"El hombre, en su orgullo, creó a Dios a su imagen y semejanza."
Friedrich Nietzsche
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:27.