Si, es correcto todo lo anterior, pero no es exactamente lo que
Raspinu necesita. Veamos:
El código original que regresa todo bien pero marca error es este:
Código:
<table width="139" border="0"><tr><th>
<% If Tabla_1.Eof Then
Response.Write "No Tenemos Datos"
Else
Do While Cint (Tabla_1.Fields ("InterpreteIDTEMA"))=Cint (Tabla_2.Fields ("IdTema")) AND Not Tabla_1.Eof %>
</th> </tr><tr><th>
+ <%Response.Write Tabla_1.Fields ("Interprete_Artista")%>
</th> </tr><tr>
<%Tabla_1.MoveNext
Loop
End If %>
Marca error por que en el mismo While pregunta por el valor del campo Tabla_1("InterpreteIDTEMA") que claro esta cuando se llega al EOF ya no existe. Ello se soluciona colocando un par de asignaciones:
Código:
<table width="139" border="0"><tr><th>
<% If Tabla_1.Eof Then
Response.Write "No Tenemos Datos"
Else
IdInterprete = CInt(Tabla_1.Fields ("InterpreteIDTEMA"))
Do While IdInterprete=Cint (Tabla_2.Fields ("IdTema")) AND Not Tabla_1.Eof %>
</th> </tr><tr><th>
+ <%Response.Write Tabla_1.Fields ("Interprete_Artista")%>
</th> </tr><tr>
<%Tabla_1.MoveNext
If Not Tabla_1.EOF Then IdInterprete = CInt(Tabla_1.Fields ("InterpreteIDTEMA")) End If
Loop
End If %>
Y listo!! (Luego pasaremos a la optimización del código) con ello la idea es la misma y el código dejara de "tronar"
Ahora veamos la sugerencia:
Cita: strSql = "SELECT Interprete_Artista "
strSql = strSql & "FROM TABLA_1 INNER JOIN TABLA_2 ON "
strSql = strSql & "(TABLA_1.INTERPRETEIDTEMA=TABLA2.IDTEMA) "
set mADO = conn.execute(strSql)
Este Query nos regresa todas las filas de Tabla_1 y Tabla_2 donde sus campos INTERPRETEIDTEMA y IDTEMA respectivamente sean iguales, pero no es lo que el ciclo original quiere:
Cita: Do While Cint (Tabla_1.Fields ("InterpreteIDTEMA"))=Cint (Tabla_2.Fields ("IdTema")) AND Not Tabla_1.Eof %>
Ahí se ve que se necesitan todos los registros de Tabla_1 cuyo campo InterpreteIDTEMA sea igual al que en el registro X corresponda al campo IdTema de la tabla_2. Es decir, algo como:
Cita: strSql = "SELECT Interprete_Artista " &_
"FROM TABLA_1 " &_
"WHERE INTERPRETEIDTEMA= " & TABLA2.IDTEMA
Tabla_1.Open strSQL, ObjConn
...
Y todo lo demás, pues ya aplica
Saludos