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

Error al imprimir datos de una consulta SQL

Estas en el tema de Error al imprimir datos de una consulta SQL en el foro de ASP Clásico en Foros del Web. Buenas, Tengo un error en una de las consultas sql en ASP, sabéis porque me arroja este error? ADODB.Recordset error '800a0cc1' Item cannot be found ...
  #1 (permalink)  
Antiguo 09/12/2009, 06:55
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 18 años, 2 meses
Puntos: 20
Error al imprimir datos de una consulta SQL

Buenas,

Tengo un error en una de las consultas sql en ASP, sabéis porque me arroja este error?

ADODB.Recordset error '800a0cc1'
Item cannot be found in the collection corresponding to the requested name or ordinal.


El objetivo es tener una tabla con el nombre del trabajador y la suma de tiempo dedicado.

He probado hacer la consulta de diferentes formas pero cuando imprimo el valor
SELECT SUM(tiempo_dedicado) AS tiempo
SELECT SUM(tiempo_dedicado) AS [tiempo]
SELECT SUM(tiempo_dedicado) AS 'tiempo'


Pero cuando imprimo el valor no lo coje bien, y sí, si pongo tiempo_dedicado, pero si utilizo tiempo_dedicado no me hace la suma

response.write("<td>" & "Dani" & "</td>" & "<td>" & rs("tiempo") & "</td>")


Código asp:
Ver original
  1. SQL = "SELECT SUM(tiempo_dedicado) AS tiempo FROM COMENTARIOS WHERE (creat_per = '12571') AND (YEAR(data) LIKE '2009') AND (DAY(data) LIKE '9') AND (MONTH(data) LIKE '12')"
  2. 'rs.open SQL, conn
  3.  
  4. 'will iterate to display the records got from the database
  5. response.write("<table>")
  6. response.write("<thead>" & "<th>" & "Trabajador" & "</th>" & "<th>" & "Tiempo en Min." & "</th>" & "</thead>")
  7. While Not rs.EOF
  8.   response.write("<tr>")
  9.   response.write("<td>" & "Dani" & "</td>" & "<td>" & rs("tiempo") & "</td>")
  10.   response.write("</tr>")
  11.   rs.MoveNext
  12. Wend
  13. response.write("</table>")

Muchas gracias de antemano!
  #2 (permalink)  
Antiguo 09/12/2009, 08:34
Avatar de JuanRAPerez
Colaborador
 
Fecha de Ingreso: octubre-2003
Mensajes: 2.393
Antigüedad: 21 años, 6 meses
Puntos: 27
Respuesta: Error al imprimir datos de una consulta SQL

toc toc


Esta línea esta como comentario en tu código

'rs.open SQL, conn

quitale el comentario y prueba

suerte
__________________
JuanRa Pérez
San Salvador, El Salvador
  #3 (permalink)  
Antiguo 09/12/2009, 08:54
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 18 años, 2 meses
Puntos: 20
Respuesta: Error al imprimir datos de una consulta SQL

Cita:
Iniciado por JuanRAPerez Ver Mensaje
toc toc


Esta línea esta como comentario en tu código

'rs.open SQL, conn

quitale el comentario y prueba

suerte
Muchas gracias JuanRAPerez por tu interés.
Quizás con el código entero me podéis aconsejar mejor. Esa linea que me dices la tengo activada más arriba, mira.

Código asp:
Ver original
  1. <%
  2.  
  3. Set conn = Server.CreateObject("ADODB.Connection")
  4. conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=xxxxxxxxxx;UID=xxxxxxx;PWD=xxxx;DATABASE=incidencias"
  5.  
  6. 'This code block will create a recordset
  7. Set rs = Server.CreateObject("ADODB.Recordset")
  8. SQL = "SELECT * FROM NSG_COMENTARIS_INCIDENCIES WHERE (creat_per = '12571') AND (YEAR(data) LIKE '2009') AND (DAY(data) LIKE '9') AND (MONTH(data) LIKE '12')"
  9. rs.open SQL, conn
  10.  
  11. 'will iterate to display the records got from the database
  12. response.write("<table>")
  13. 'response.write("<thead>" & "<th>" & "ID_Comentari" & "</th>" & "<th>" & "ID_Incidencia" & "</th>" & "<th>" & "Data" & "</th>" & "<th>" & "Descripcio" & "</th>" & "<th>" & "Temps Dedicat" & "</th>" & "<th>" & "Creat Per" & "</th>" & "</thead>")
  14. response.write("<thead>" & "<th>" & "ID_Comentari" & "</th>" & "<th>" & "ID_Incidencia" & "</th>" & "<th>" & "Data" & "</th>" & "<th>" & "Temps Dedicat" & "</th>" & "<th>" & "Creat Per" & "</th>" & "</thead>")
  15.  
  16. While Not rs.EOF
  17.   response.write("<tr>")
  18.   'response.write("<td>" & rs("id_comentari") & "</td>" & "<td>" & rs("id_incidencia") & "</td>" & "<td>" & rs("data") & "</td>" & "<td>" & rs("descripcio") & "</td>" & "<td>" & rs("temps_dedicat") & "</td>" & "<td>" & rs("creat_per") & "</td>")
  19.   response.write("<td>" & rs("id_comentari") & "</td>" & "<td>" & rs("id_incidencia") & "</td>" & "<td>" & rs("data") & "</td>" & "<td>" & rs("temps_dedicat") & "</td>" & "<td>" & rs("creat_per") & "</td>")
  20.  
  21.   response.write("</tr>")
  22.   rs.MoveNext
  23. Wend
  24. response.write("</table>")
  25. 'closes the connection
  26. rs.close
  27. conn.close
  28. Set rs = Nothing
  29. Set conn = Nothing
  30.  
  31.  
  32. 'imprimo usuarios con sus tiempos
  33. Set conn = Server.CreateObject("ADODB.Connection")
  34. conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=xxxxxxxxxx;UID=xxxxxxx;PWD=xxxx;DATABASE=incidencias"
  35.  
  36. Set rs = Server.CreateObject("ADODB.Recordset")
  37. rs.open SQL, conn
  38. SQL = "SELECT SUM(temps_dedicat) AS tiempos FROM NSG_COMENTARIS_INCIDENCIES WHERE (creat_per = '12571') AND (YEAR(data) LIKE '2009') AND (DAY(data) LIKE '9') AND (MONTH(data) LIKE '12')"
  39. 'rs.open SQL, conn
  40.  
  41. 'will iterate to display the records got from the database
  42. response.write("<table>")
  43. response.write("<thead>" & "<th>" & "Trabajador" & "</th>" & "<th>" & "Tiempo en Min." & "</th>" & "</thead>")
  44. While Not rs.EOF
  45.   response.write("<tr>")
  46.   response.write("<td>" & "Dani" & "</td>" & "<td>" & rs("tiempos") & "</td>")
  47.   response.write("</tr>")
  48.   rs.MoveNext
  49. Wend
  50. response.write("</table>")
  51.  
  52.  
  53. 'closes the connection
  54. rs.close
  55. conn.close
  56. Set rs = Nothing
  57. Set conn = Nothing
  58.  
  59. %>

Muchas gracias de antemano!
  #4 (permalink)  
Antiguo 09/12/2009, 09:12
Avatar de JuanRAPerez
Colaborador
 
Fecha de Ingreso: octubre-2003
Mensajes: 2.393
Antigüedad: 21 años, 6 meses
Puntos: 27
Respuesta: Error al imprimir datos de una consulta SQL

ok, entonces es obvio no existe el campo

El recordset se crea aquí:
Código ASP:
Ver original
  1. SQL = "SELECT * FROM NSG_COMENTARIS_INCIDENCIES WHERE (creat_per = '12571') AND (YEAR(data) LIKE '2009') AND (DAY(data) LIKE '9') AND (MONTH(data) LIKE '12')"
  2. rs.open SQL, conn

Este nunca se crea:
Código ASP:
Ver original
  1. 'aqui la creas de nuevo pero con el SQL anterior
  2. rs.open SQL, conn
  3. SQL = "SELECT SUM(temps_dedicat) AS tiempos FROM NSG_COMENTARIS_INCIDENCIES WHERE (creat_per = '12571') AND (YEAR(data) LIKE '2009') AND (DAY(data) LIKE '9') AND (MONTH(data) LIKE '12')"
  4. 'este RS nunca se crea...
  5. 'rs.open SQL, conn

asi que tu problema es este.

1 adicionas el SUM(temps_dedicat) AS tiempos en tu primer SQL
2 creas un nuevo rs para la segunda consulta.

suerte
__________________
JuanRa Pérez
San Salvador, El Salvador
  #5 (permalink)  
Antiguo 09/12/2009, 10:53
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 18 años, 2 meses
Puntos: 20
Respuesta: Error al imprimir datos de una consulta SQL

Cita:
Iniciado por JuanRAPerez Ver Mensaje
ok, entonces es obvio no existe el campo

El recordset se crea aquí:
Código ASP:
Ver original
  1. SQL = "SELECT * FROM NSG_COMENTARIS_INCIDENCIES WHERE (creat_per = '12571') AND (YEAR(data) LIKE '2009') AND (DAY(data) LIKE '9') AND (MONTH(data) LIKE '12')"
  2. rs.open SQL, conn

Este nunca se crea:
Código ASP:
Ver original
  1. 'aqui la creas de nuevo pero con el SQL anterior
  2. rs.open SQL, conn
  3. SQL = "SELECT SUM(temps_dedicat) AS tiempos FROM NSG_COMENTARIS_INCIDENCIES WHERE (creat_per = '12571') AND (YEAR(data) LIKE '2009') AND (DAY(data) LIKE '9') AND (MONTH(data) LIKE '12')"
  4. 'este RS nunca se crea...
  5. 'rs.open SQL, conn

asi que tu problema es este.

1 adicionas el SUM(temps_dedicat) AS tiempos en tu primer SQL
2 creas un nuevo rs para la segunda consulta.

suerte
Buenas,

Gracias! lo conseguí solucionar comentando la linea 2 y descomentando la linea 5 de tu "ultimo trozo de código"

Por otro lado, ¿existe alguna forma de hacerlo sin tener que cerrar y volver abrir toda la conexión, usando user y pass 2 veces, etc...?

Muchas gracias de antemano!
  #6 (permalink)  
Antiguo 09/12/2009, 11:02
Avatar de JuanRAPerez
Colaborador
 
Fecha de Ingreso: octubre-2003
Mensajes: 2.393
Antigüedad: 21 años, 6 meses
Puntos: 27
Respuesta: Error al imprimir datos de una consulta SQL

yeap

la idea báse es

creas conexión
creas el rs

haces tu sql
abres el rs
imprimes registros

haces otra sql
abres el rs con esa otra sql
imprimes registros

cierras rs
cierrras coenxion

suerte
__________________
JuanRa Pérez
San Salvador, El Salvador
  #7 (permalink)  
Antiguo 10/12/2009, 02:24
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 18 años, 2 meses
Puntos: 20
Respuesta: Error al imprimir datos de una consulta SQL

Cita:
Iniciado por JuanRAPerez Ver Mensaje
yeap

la idea báse es

creas conexión
creas el rs

haces tu sql
abres el rs
imprimes registros

haces otra sql
abres el rs con esa otra sql
imprimes registros

cierras rs
cierrras coenxion

suerte
Creo que te refererias a esto, pero me falla la última consulta

Código asp:
Ver original
  1. <%
  2.  
  3. Set conn = Server.CreateObject("ADODB.Connection")
  4. conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=xxxxxxxxxx;UID=xxxxxxx;PWD=xxxx;DATABASE=incidencias"
  5.  
  6. 'This code block will create a recordset
  7. Set rs = Server.CreateObject("ADODB.Recordset")
  8. SQL = "SELECT * FROM NSG_COMENTARIS_INCIDENCIES WHERE (creat_per = '12571') AND (YEAR(data) LIKE '2009') AND (DAY(data) LIKE '9') AND (MONTH(data) LIKE '12')"
  9. rs.open SQL, conn
  10.  
  11. 'will iterate to display the records got from the database
  12. response.write("<table class='left'>")
  13. 'response.write("<thead>" & "<th>" & "ID_Comentari" & "</th>" & "<th>" & "ID_Incidencia" & "</th>" & "<th>" & "Data" & "</th>" & "<th>" & "Descripcio" & "</th>" & "<th>" & "Temps Dedicat" & "</th>" & "<th>" & "Creat Per" & "</th>" & "</thead>")
  14. response.write("<thead>" & "<th>" & "ID_Comentari" & "</th>" & "<th>" & "ID_Incidencia" & "</th>" & "<th>" & "Data" & "</th>" & "<th>" & "Temps Dedicat" & "</th>" & "<th>" & "Creat Per" & "</th>" & "</thead>")
  15.  
  16. While Not rs.EOF
  17.   response.write("<tr>")
  18.   'response.write("<td>" & rs("id_comentari") & "</td>" & "<td>" & rs("id_incidencia") & "</td>" & "<td>" & rs("data") & "</td>" & "<td>" & rs("descripcio") & "</td>" & "<td>" & rs("temps_dedicat") & "</td>" & "<td>" & rs("creat_per") & "</td>")
  19.   response.write("<td>" & rs("id_comentari") & "</td>" & "<td>" & rs("id_incidencia") & "</td>" & "<td>" & rs("data") & "</td>" & "<td>" & rs("temps_dedicat") & "</td>" & "<td>" & rs("creat_per") & "</td>")
  20.  
  21.   response.write("</tr>")
  22.   rs.MoveNext
  23. Wend
  24. response.write("</table>")
  25. 'closes the connection
  26. 'rs.close
  27. 'conn.close
  28. 'Set rs = Nothing
  29. 'Set conn = Nothing
  30.  
  31.  
  32. 'imprimo usuarios con sus tiempos
  33. 'Set conn = Server.CreateObject("ADODB.Connection")
  34. 'conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=sqlvs1.datacenter.nexica.com;UID=pectra_tiempos;PWD=jupiter;DATABASE=Nsg_Enric"
  35.  
  36. 'Set rs = Server.CreateObject("ADODB.Recordset")
  37. 'rs.open SQL, conn
  38. SQL = "SELECT SUM(temps_dedicat) AS tiempos FROM NSG_COMENTARIS_INCIDENCIES WHERE (creat_per = '12571') AND (YEAR(data) LIKE '2009') AND (DAY(data) LIKE '9') AND (MONTH(data) LIKE '12')"
  39. rs.open SQL, conn
  40.  
  41. 'will iterate to display the records got from the database
  42. response.write("<table class='right'>")
  43. response.write("<thead>" & "<th>" & "Trabajador" & "</th>" & "<th>" & "Tiempo en Min." & "</th>" & "</thead>")
  44. While Not rs.EOF
  45.   response.write("<tr>")
  46.   response.write("<td>" & "Dani" & "</td>" & "<td>" & rs("tiempos") & "</td>")
  47.   response.write("</tr>")
  48.   rs.MoveNext
  49. Wend
  50. response.write("</table>")
  51.  
  52.  
  53. 'closes the connection
  54. rs.close
  55. conn.close
  56. Set rs = Nothing
  57. Set conn = Nothing
  58.  
  59. %
>

ADODB.Recordset error '800a0e79'
Operation is not allowed when the object is open.
/script.asp, line 115

Esa linea esta de la segunda consulta, corresponde a las linea 39 del script del post
rs.open SQL, conn

Muchas gracias de antemano!
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 08:14.