Saludos a todos:
A ver si pueden ayudarme, de verdad que lo necesito ya que no doy con el tema.
Veran tengo un formulario que tiene que borrar datos en dos tablas, además de los ficheros a los que se hace referencia en la tabla del recordset RS:
Estas tablas son:
Tabla Recordset
------------- ----------
hotelesturismo RS
clientes RS1
tarifasturismo RS2
El formulario de borrar lanza un filtro dependiendo de los campos que estén cubiertos. Este filtro se aplica para seleccionar los registros que se van a borrar.
Antes de borrarlos hago que borre los archivos a los que se hace referencia en la tabla hotelesturismo.
Hasta aquí todo bien.
El problema viene porque en la tabla tarifasturismo se deben borrar todos los registros que cumplen que el campo comun de las tablas hotelesturismo y tarifasturismo (referenciahotelcasa) sea identico.
Les paso el código a ver si me pueden dar alguna pista. He desabilitado los rs.close y conn.close porque de tantos cambios que he hecho deben haberme quedado colgados y si los activo me da un error, pero eso ya lo revisaré al final.
He puesto dos tablas para poder ver los registros que se borran antes de borrarlos.
El error que me devuelve es:
error '80020009' Ocurrió una excepción. line 120 Marco la línea 120 en verde y el código que tiene que encontrar los registros a borrar de la tabla tarifasturismo en rojo
Ante todo muchísimas gracias.
Código:
<body
<!--#INCLUDE file="../../../adovbs.asp"-->
<%IF (request.form <> "") then
'Para conexión a dsn arsys con ACCESS
set Conn= Server.CreateObject("ADODB.Connection")
Conn.ConnectionString = "DSN=clubviajesoferta.com.turofertas"
Conn.open
Set RS=Server.CreateObject("ADODB.Recordset")
rs.activeconnection=Conn
rs.source="hotelesturismo"
rs.Locktype = adLockOptimistic
rs.CursorType = adOpenDinamic
rs.open
'Termina aquí la conexion a dsn arsys con ACCESS
Set RS2=Server.CreateObject("ADODB.Recordset")
rs2.activeconnection=Conn
rs2.source="tarifasturismo"
rs2.Locktype = adLockOptimistic
rs2.CursorType = adOpenDinamic
rs2.open
Poner_AND= False
Filtro= ""
FOR EACH Parametro IN Request.Form
IF Request.Form (Parametro) <> "" THEN
IF Poner_AND THEN
Filtro= Filtro & " AND " & Parametro & "='"
Filtro= Filtro & Request.Form(Parametro) & "'"
ELSE
Filtro= Filtro & Parametro & "='"
Filtro= Filtro & Request.Form(Parametro) & "'"
Poner_AND = True
END IF
END IF
NEXT
Filtro=Lcase(filtro)
response.write "Filtro rs: " & filtro & "<br>"
rs.filter= Filtro
if rs.bof and rs.eof then
No se encontraron coincidencias con la búsqueda solicitada
else%>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr bgcolor="#e0e0e0">
<td width="17%"> <div align="left"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">Referencia</font></div></td>
<td width="33%"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">Nombre</font></td>
<td width="8%"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">Localidad</font></td>
</tr>
<%response.write ("Se han borrados los siguientes registros de la tabla hotelesturismo<p>")
rs.movefirst
do while not rs.eof
if colorfila=0 then
color="#EEF0F7"
colorfila=1
else
color="FFFFFF"
colorfila=0
end if %>
<tr valign="top" bgcolor="<%=color%>">
<td><font size="2" face="Arial, Helvetica, sans-serif"><%=RS("referenciahotelcasa")%></font></td>
<td><div align="justify"><font size="2" face="Arial, Helvetica, sans-serif"><%=RS("empresanombrecomercial")%></font></div></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"><%=RS("localidad")%></font></td>
</tr>
<%rs.movenext
loop%>
</table>
<%'Borrar los registros del RS2
'response.write "<br>La referencia que tiene que borrar es: " & rs("referenciahotelcasa") & "<br>"
Sqlstring="select * from tarifasturismo where referenciahotelcasa=" & "'" &rs("referenciahotelcasa")& "'"
rs2.filter=Sqlstring
if rs2.bof and rs2.eof then
response.write("<br><br><div align=""center""><font face= ""Arial, Helvetica, sans-serif"" size=""3"" color=""#FB4C50""><strong>No se encontraron coincidencias con la búsqueda solicitada </strong></font></div>")
else%>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr bgcolor="#e0e0e0">
<td width="17%"> <div align="left"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">Identificadro</font></div></td>
<td width="33%"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">Referencia</font></td>
<td width="8%"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">tanohabitaciondoblebano</font></td>
</tr>
<%response.write ("Se borrarán los siguientes registros de la tabla Tarifasturismo<p>")
rs2.movefirst
do while not rs2.eof
if colorfila=0 then
color="#EEF0F7"
colorfila=1
else
color="FFFFFF"
colorfila=0
end if %>
<tr valign="top" bgcolor="<%=color%>">
<td><%=RS2("identificadoroferta")%></font></td>
<td><%=RS2("referenciahotelcasa")%></font></td>
<td><%=RS2("tanohabitaciondoblebano")%></td>
</tr>
<%rs2.movenext
loop
end if%>
</table>
<%rs.movefirst
do while not rs.eof
'Construimos la ruta y el nombre del fichero que se va a borrar del servidor y
'que previamente escogimos mediante el formulario de borrar registros
cadenaorigen=rs("imagen")
if cadenaorigen <> "" then
cadenabuscar="../../"
'cadenacambiar="C:\Inetpub\vhosts\turofertas.com\httpdocs\"
cadenacambiar="c:/obradoiroweb/obradoiroweb/Turofertas/"
rutaimagenaborrar=replace(cadenaorigen,cadenabuscar,cadenacambiar,1,1,1)
set FSO=CreateObject("Scripting.FileSystemObject")
set file=fso.GetFile(rutaimagenaborrar)
file.delete
end if
cadenaorigen1=rs("imagen1")
if cadenaorigen1 <> "" then
cadenabuscar1="../../"
'cadenacambiar1="C:\Inetpub\vhosts\turofertas.com\httpdocs\"
cadenacambiar1="c:/obradoiroweb/obradoiroweb/Turofertas/"
rutaimagenaborrar1=replace(cadenaorigen1,cadenabuscar1,cadenacambiar1,1,1,1)
set file=fso.GetFile(rutaimagenaborrar1)
file.delete
end if
cadenaorigen2=rs("imagentarifario")
if cadenaorigen2 <> "" then
cadenabuscar2="../../"
'cadenacambiar2="C:\Inetpub\vhosts\turofertas.com\httpdocs\"
cadenacambiar2="c:/obradoiroweb/obradoiroweb/Turofertas/"
rutaimagenaborrar2=replace(cadenaorigen2,cadenabuscar2,cadenacambiar2,1,1,1)
set file=fso.GetFile(rutaimagenaborrar2)
file.delete
end if
'Borramos el registro seleccionado en el formulario de borrar registros
rs.delete
'Borra siempre el primer registro del filtro
rs.movefirst
loop
end if
end if
'rs.close
'rs2.close
'Conn.close%>
<%ELSE
set Conn1= Server.CreateObject("ADODB.Connection")
Set RS1=Server.CreateObject("ADODB.Recordset")
Conn1.ConnectionString = "DSN=clubviajesoferta.com.turofertas"
Sqlstring="select empresanombrefiscal from clientes where nombreusuario=" & "'" &nombreusuario& "'"
Conn1.open
Set RS1 = conn1.execute (sqlstring)
response.write "La empresa es: " & tipo = rs1("empresanombrefiscal")%>
Rellene el campo por el cual desea realizar la búsqueda </p>
<form name="form1" method="post" action="borrar_turismo.asp?nombreusuario=<%=nombreusuario%>">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="12%">Referencia</td>
<td colspan="6"><input name="referenciahotelcasa" type="text" tabindex="1" id="referenciahotelcasa" size="10" maxlength="10"></td>
</tr>
<tr>
<td>Nombre Fiscal </td>
<td colspan="6"><input name="empresanombrefiscal" type="text" id="empresanombrefiscal" onfocus="blur()" value="<%=rs1("empresanombrefiscal")%>"></td>
</tr>
<tr>
<td><p>Nombre Comercial </p></td>
<td colspan="3"><input name="empresanombrecomercial" type="text" id="empresanombrecomercial" tabindex="2" size="35" maxlength="35"></td>
<%if session("autorizacion") = 5 then%>
<td>Grupo</td>
<td width="1%"><select name="grupocasa" id="grupocasa">
<option value="ph">Pazos-Hospedería</option>
<option value="pr">Pazos-Residencia</option>
<option value="ch">Casas-Hospedería</option>
<option value="cr">Casas-Residencia</option>
<option value="ca">Casas de Aldea</option>
</select></td>
<%else%>
<td width="20%">Categoría
<input name="categoriahotel" type="text" id="categoriahotel" size="1" maxlength="1">
<img src="../../../images/iconos/estrellas.gif" width="22" height="22" align="absbottom"></td>
<%end if%>
</tr>
<tr>
<td>Localidad</td>
<td width="28%"><input name="localidad" type="text" id="localidad" size="35" maxlength="35"></td>
<td width="17%"> </td>
<td width="11%"> </td>
<td width="11%">Provincia</td>
<td colspan="2"><input name="provincia" type="text" id="provincia" size="20" maxlength="20"></td>
</tr>
<tr>
<td>Teléfono</td>
<td><input name="telefono" type="text" id="telefono" size="9" maxlength="9"></td>
<td>Teléfono 1</td>
<td><input name="telefono1" type="text" id="telefono1" size="9" maxlength="9"></td>
<td>Fax</td>
<td colspan="2"><input name="fax" type="text" id="fax" size="9" maxlength="9"></td>
</tr>
<tr>
<td colspan="7"><div align="center">
<input type="submit" value="Borrar Hotel/Turismo Rural">
<input type="reset" value="Limpiar Formulario">
</div></td>
</tr>
</table>
</form>
<%END IF
'rs1.close
'conn1.close%>
</body>
</html>