Saludos:
Tengo aquí un código que me está dando un problema a ver si ustedes pueden ayudarme con él porque ya llevo 7 horas encima y no he encontrado la solución.
La cosa es un poco complicada, pero a ver si me explico:
La selección de los registros a borrar se hace con la propiedad rs.filter que viene de un formulario por el que los usuarios van discriminando los registros que se borraràn más tarde.
El asunto es que además de borrar el conjunto de registros arriba mencionado debe borrar el resto de los registros donde el campo imagenofertareferida es igual al contenido del campo imagenoferta (para esto uso el rs2) que proviene de la criba anterior.
Además debe borrar también las imágenes de las diferentes ofertas, pero aquí no hay problema.
Ya he conseguido que liste bien todo lo que tiene que borrar pero a la hora de borrarlo me devuelve el error siguiente y la línea donde da el error es la que marco en rojo.
Espero que me entiendan y puedan echarme una mano.
ADODB.Recordset
error '800a0cb3' El Recordset actual no admite actualizaciones. Puede ser una limitación del proveedor o del tipo de bloqueo seleccionado. /gestion_mayoristas/ofertas/borrar/borrar_ofertas_mayoristas.asp, line 149
Código:
<file:///C|/obradoiroweb/obradoiroweb/images/frame_izqda_con_opacidad.jpg" leftmargin="5" topmargin="5" marginwidth="5" marginheight="5">
<!--Incluimos el fichero de constantes-->
<!--#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="ofertasmayoristas"
rs.Locktype = adLockOptimistic
rs.CursorType = adOpenDinamic
rs.open
function CortarNombreFichero
imagen=rs("imagenoferta")
len(imagen)
posicioncaracterbuscar=instrrev(imagen,"/")+1
response.write mid(imagen,posicioncaracterbuscar)
end function
Poner_AND= False
'El Codigo siguiente hace que si el formulario se envia vacio no se borre toda la tabla
Vacio=true
For each parametro in request.form
parametro = Lcase(parametro)
if request.form(parametro) <> "" then
vacio = false
exit for
end if
next
if vacio=true then
response.write("Operación no permitida.<br> Al dejar todos los campos vacios, ha intentado borrar la tabla completa")
end if
if not vacio then
'Termina el codigo de comprobacion del formulario vacio para no borrar toda la tabla
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)
rs.filter= Filtro
response.write "el filtro es: " & filtro
'Abrimos el recordset RS2
set Conn2= Server.CreateObject("ADODB.Connection")
Set RS2=Server.CreateObject("ADODB.Recordset")
Conn2.ConnectionString = "DSN=clubviajesoferta.com.turofertas"
sqlstring2="select * from ofertasmayoristas where imagenofertareferida=" & "'" & rs("imagenoferta") & "'"
Conn2.open
%>
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<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">Denominación</font></td>
<td width="8%"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">Empresa</font></td>
<td width="13%"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">Imagen</font></td>
<td width="16%"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">Publicación</font></td>
<td width="13%"><font color="#003399" size="2" face="Arial, Helvetica, sans-serif">Validez</font></td>
</tr>
<%if rs.bof and rs.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
response.write ("Se han borrados las siguientes ofertas: <p> borrarofertasmayoristas.asp")
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("referenciaoferta")%></font></td>
<td><div align="justify"><font size="2" face="Arial, Helvetica, sans-serif"><%=RS("denominacionoferta")%></font></div></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"><%=RS("empresaoferta")%></font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"><%CortarNombreFichero%></font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"><%=RS("fechapublicacionoferta")%></font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"><%=RS("fechavalidezoferta")%></font></td>
</tr>
<%rs.movenext
loop%>
</table>
<%
rs.movefirst
'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("imagenoferta")
cadenabuscar="../../"
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
'Este código borrar los registros de los minoristas que tienen ofertas referidas
do while not rs.eof
response.write "<br>Con la orden: <br> " & sqlstring2 & "<br> se borraran los registros de los minoristas:<br>"
Set RS2= conn2.execute (sqlstring2)
rs2.movefirst
if not rs2.bof and not rs2.eof then
rs2.movefirst
do while not rs2.eof
response.write RS2("referenciaoferta") & "<br>"
rs2.delete
rs2.movenext
loop
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%>
<br>
<A HREF="../../../modulo_gestion.asp?nombreusuario=<%=nombreusuario%>" target="_parent">Menu principal </A> ** <A HREF="borrar_ofertas.asp?nombreusuario=<%=nombreusuario%>" target="_parent">Borrar Oferta</A>
<%
rs.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: " & categoria = rs1("empresanombrefiscal")
%>
Rellene el campo por el cual desea realizar la búsqueda </p>
<form name="form1" method="post" action="borrar_ofertas_mayoristas.asp?nombreusuario=<%=nombreusuario%>">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="23%">Referencia</td>
<td colspan="3"><input name="referenciaoferta" type="text" id="referenciaoferta" size="20" maxlength="20"></td>
</tr>
<tr>
<td>Denominación</td>
<td colspan="3"><input name="denominacionoferta" type="text" id="denominacionoferta" size="11" maxlength="11"></td>
</tr>
<tr>
<td>Destino</td>
<td colspan="3"><select name="destinooferta" id="destinooferta">
<option value="""" selected>Seleccione un destino</option>
<option value="2 x 1 Ofertas">2 x 1 Ofertas</option>
<option value="Africa">África</option>
<option value="America">América</option>
<option value="Canarias">Canarias</option>
<option value="Caribe">Caribe</option>
<option value="Cruceros">Cruceros</option>
<option value="Europa">Europa</option>
<option value="Ferias">Ferias</option>
</select></td>
</tr>
<tr>
<td>Empresa</td>
<td colspan="3"><input name="empresaoferta" type="text" onfocus="blur()" id="empresaoferta" value="<%=rs1("empresanombrefiscal")%>" size="35" maxlength="35"></td>
</tr>
<tr>
<td>Fecha Publicación</td>
<td width="13%"><input name="fechapublicacionoferta" type="text" id="fechapublicacionoferta" size="10" maxlength="10"></td>
<td width="4%"><img src="../../../images/iconos/ayuda.gif" width="16" height="20"></td>
<td width="60%"><font size="2" face="Arial, Helvetica, sans-serif">DD/MM/AAAA</font></td>
</tr>
<tr>
<td>Fecha Validez</td>
<td><input name="fechavalidezoferta" type="text" id="fechavalidezoferta" size="10" maxlength="10"> </td>
<td><img src="../../../images/iconos/ayuda.gif" width="16" height="20"></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">DD/MM/AAAA</font></td>
</tr>
<tr>
<td> </td>
<td colspan="3"><input type="submit" value="Borrar Oferta" onClick="return window.confirm('Eliminar el/los registro/s')">
<input type="reset" value="Limpiar Formulario"></td>
</tr>
</table>
</form>
<%END IF%>
</body>
</html>
Muchas gracias a todos