Cita:
Iniciado por Myakire
Ok, no abres el rs de solo lectura, entonces el addnew no creo que sea el que da error, y menos por que el error que manda pareciera que lo hace en el .Open ...
Cuál es el QueryString del recordSet?
Perdon que sea tan largo pero me como no tengo mucha idea de asp prefiero enviarte el codigo entero. El tema es que el inmueble ya publicado con su foto al querer agregarle otra foto me sale el error.
CODIGO:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Grupo inmobiliario</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<% if session("autorizado") <> true then
response.redirect "index.asp"
end if%>
<div class="gContenedor" align="center">
<div class="contenedor2" >
<div class="contenedor" >
<!--#include file="includes/header.asp"-->
<div class="separador"></div>
<!-- pepo aca va el contenido de cada sección-->
<div class="center" align="left">
<div class="barraMain"> Agregar nueva propiedad - paso 3 - subir imagenes </div>
<br>Para una correcta visualización se recomienda subir imagenes cuyo tamaño no sea superior a <strong>640 x 480 pixeles</strong>.<br>
<br>
<div class="banner3"><br>
<%response.buffer=true
Func = Request("Func")
if isempty(Func) Then
Func = 1
End if
Select Case Func
Case 1
link = request.QueryString("id")
%>
<FORM ENCTYPE="multipart/form-data" ACTION="subirimagenes.asp?func=2&id=<%= request.QueryString("id") %>" METHOD=POST id=form1 name=form1>
<TABLE width="325" border="1" align="center" cellpadding="5" cellspacing="5" class="tit5">
<TR>
<TD>
<p><b>Instrucciones:</b></p>
<ol>
<li>Pulsa en el botón examinar y elige la imagen que deseas.</li>
<li>Luego pulsa el botón subir. </li>
<li>Espere, recibirá la notificación
al terminar de subir el archivo.</li>
</ol></TD>
</TR>
<TR>
<TD ><STRONG>Nombre
de la imagen a subir ...</STRONG> <br>
<br>
<INPUT NAME=File1 SIZE=20 TYPE=file>
</font>
<INPUT type="submit" value="Subir"></TD>
</TR>
</TABLE>
<table width="0" border="0" align="center">
<tr>
<td> </td>
<td><a href="userP.asp"><img src="img/saltpaso.gif" border="0"></a></td>
<td> </td>
</tr>
</table>
</FORM>
<p>
<%
Case 2
ForWriting = 2
adLongVarChar = 201
lngNumberUploaded = 0
'Get binary data from form
noBytes = Request.TotalBytes
binData = Request.BinaryRead (noBytes)
'convery the binary data to a string
Set RST = CreateObject("ADODB.Recordset")
LenBinary = LenB(binData)
if LenBinary > 0 Then
RST.Fields.Append "myBinary", adLongVarChar, LenBinary
RST.Open
RST.AddNew
RST("myBinary").AppendChunk BinData
RST.Update
strDataWhole = RST("myBinary")
End if
'Creates a raw data file for with all
' data sent. Uncomment for debuging.
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f = fso.OpenTextFile(server.mappath(".") & "\raw.txt", ForWriting, True)
'f.Write strDataWhole
'set f = nothing
'set fso = nothing
'get the boundry indicator
strBoundry = Request.ServerVariables ("HTTP_CONTENT_TYPE")
lngBoundryPos = instr(1,strBoundry,"boundary=") + 8
strBoundry = "--" & right(strBoundry,len(strBoundry)-lngBoundryPos)
'Get first file boundry positions.
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
Do While lngCurrentEnd > 0
'Get the data between current boundry an
' d remove it from the whole.
strData = mid(strDataWhole,lngCurrentBegin, lngCurrentEnd - lngCurrentBegin)
strDataWhole = replace(strDataWhole,strData,"")
'Get the full path of the current file.
lngBeginFileName = instr(1,strdata,"filename=") + 10
lngEndFileName = instr(lngBeginFileName,strData,chr(34))
'Make sure they selected at least one fi
' le.
if lngBeginFileName = lngEndFileName and lngNumberUploaded = 0 Then
Response.Write "<H2> Ha ocurrido el siguiente error.</H2>"
Response.Write "Debes elegir un archivo para subir"
Response.Write "<BR><BR>Pulsa el botón volver, realiza la corrección."
Response.Write "<BR><BR><INPUT type='button' onclick='history.go(-1)' value='<< Volver' id='button'1 name='button'1>"
Response.End
End if
'There could be one or more empty file b
' oxes.
if lngBeginFileName <> lngEndFileName Then
strFilename = mid(strData,lngBeginFileName,lngEndFileName - lngBeginFileName)
'Creates a raw data file with data betwe
' en current boundrys. Uncomment for debug
' ing.
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f = fso.OpenTextFile(server.mappath(".") & "\raw_" & lngNumberUploaded & ".txt", ForWriting, True)
'f.Write strData
'set f = nothing
'set fso = nothing
'Loose the path information and keep just the file name.
tmpLng = instr(1,strFilename,"\")
Do While tmpLng > 0
PrevPos = tmpLng
tmpLng = instr(PrevPos + 1,strFilename,"\")
Loop
FileName = right(strFilename,len(strFileName) - PrevPos)
'Get the begining position of the file data sent.
'if the file type is registered with the browser then there will be a Content-Type
lngCT = instr(1,strData,"Content-Type:")
if lngCT > 0 Then
lngBeginPos = instr(lngCT,strData,chr(13) & chr(10)) + 4
Else
lngBeginPos = lngEndFileName
End if
'Get the ending position of the file dat
' a sent.
lngEndPos = len(strData)
'Calculate the file size.
lngDataLenth = lngEndPos - lngBeginPos
'Get the file data
strFileData = mid(strData,lngBeginPos,lngDataLenth)
'Create the file.
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(server.mappath("imagenes") & "/" & FileName,ForWriting, True)
f.Write strFileData
Set f = nothing
Set fso = nothing
lngNumberUploaded = lngNumberUploaded + 1
End if
'Get then next boundry postitions if any
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
loop
Response.Write "Archivo subido <BR>"
Response.Write "El archivo ya está en el servidor.<BR>"
Response.Write "Elegir la siguiente imagen.<BR>" %>
<a href="userP.asp" class="tit5"><img src="img/misprop.gif" border="0"></a> <a href="subirimagenes.asp?id=<%= request.QueryString("id") %>" class="tit5"><img src="img/misimag.gif" border="0"></a>
<%
base= "PROVIDER=Microsoft.jet.oledb.4.0;data source="& server.mappath("includes/inmobiliaria.mdb")&";"
sql = " select * from imagen where imagen.[idpropiedad]=" & request.QueryString("id") &"; "
set rs=server.CreateObject("ADODB.Recordset")
rs.open sql, base, 2,3
do while not rs.eof
if rs.fields("principal")="si" then
existePrincipal = true
end if
rs.movenext
loop
rs.Addnew
rs.fields("imagen") = FileName
rs.fields("idPropiedad") = request.QueryString("id")
if existePrincipal = true then
rs.fields("principal") = "no"
else
rs.fields("principal") = "si"
end if
rs.Update
rs.close
End Select
%>
<br>
<br>
</div>
</div><!--cierre center-->
<!-- -->
<!--#include file="includes/left.asp"-->
<div class="separador"></div>
</div><!--cierre contenedor-->
</div><!--cierre contenedor2-->
</div><!--cierre gContenedor-->
</body>
</html>