Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/08/2010, 12:24
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: actualizar multiples registros

Hola

Prueba con este ejemplo para que entiendas como ha de funcionar
Código HTML:
Ver original
  1. </head>
  2. <form action="tarifes_admin.asp?accio=edita" method="post">
  3. <table border="1px">
  4. <tr>
  5. <td>Noticia</td>
  6. <td>Mes</td>
  7. <td>Fecha / Hora</td>
  8. <td>Actualizada (Fecha /Hora)</td>
  9. <tr></tr>
  10. <td><textarea id="txtarea1" name="cam_form" tabindex="1"></textarea></td>
  11. <td><input type="text" id="txt1" name="cam_form" value="" tabindex="2" /></td>
  12. <td><input type="text" id="txt11" name="cam_form" value="" tabindex="3" /></td>
  13. <td><input type="text" id="txt111" name="cam_form" value="" tabindex="4" /></td>
  14. <tr></tr>
  15. <td><textarea id="txtarea2" name="cam_form" tabindex="5"></textarea></td>
  16. <td><input type="text" id="txt2" name="cam_form" value="" tabindex="6" /></td>
  17. <td><input type="text" id="txt22" name="cam_form" value="" tabindex="7" /></td>
  18. <td><input type="text" id="txt222" name="cam_form" value="" tabindex="8" /></td>
  19. <tr></tr>
  20. <td><textarea id="txtarea3" name="cam_form" tabindex="9"></textarea></td>
  21. <td><input type="text" id="txt3" name="cam_form" value="" tabindex="10" /></td>
  22. <td><input type="text" id="txt33" name="cam_form" value="" tabindex="11" /></td>
  23. <td><input type="text" id="txt333" name="cam_form" value="" tabindex="12" /></td>
  24. <tr></tr>
  25. <td><textarea id="txtarea4" name="cam_form" tabindex="13"></textarea></td>
  26. <td><input type="text" id="txt4" name="cam_form" value="" tabindex="14" /></td>
  27. <td><input type="text" id="txt44" name="cam_form" value="" tabindex="15" /></td>
  28. <td><input type="text" id="txt444" name="cam_form" value="" tabindex="16" /></td>
  29. <tr></tr>
  30. <td colspan="4">
  31. <input type="submit"  value="Enviar" />
  32. </td>
  33. <tr>
  34. </form>
  35. </body>
  36. </html>
tarifes_admin.asp
Código ASP:
Ver original
  1. <&#37;
  2. Dim Arr() ' Valores de todos los campos recibidos
  3. For each campo in Request.Form
  4. valCampos = valCampos & Request.Form(campo)
  5. Next
  6.  
  7. division = Split(valCampos, ",")
  8.  
  9. for i = 0 to UBound(division)
  10. Redim preserve Arr(i+1)
  11. Arr(i) = Trim(division(i))
  12. next
  13.  
  14. Dim Arr2() ' Valores del primer campo de cada tr
  15. Dim Arr3() ' Valores del segundo campo de cada tr
  16. Dim Arr4() ' Valores del tercer campo de cada tr
  17. Dim Arr5() ' Valores del cuarto campo de cada tr
  18.  
  19. j = 0
  20. for i = 0 to ubound(Arr)-1 step 4
  21. if Arr(i) <> "" then
  22. Redim preserve Arr2(j)
  23. Arr2(j) = Arr(i)
  24. j = j +1
  25. end if
  26. next
  27.  
  28. x = 0
  29. for i = 1 to ubound(Arr)-1 step 4
  30. if Arr(i) <> "" then
  31. Redim preserve Arr3(x)
  32. Arr3(x) = Arr(i)
  33. x = x +1
  34. end if
  35. next
  36.  
  37.  
  38. p = 0
  39. for i = 2 to ubound(Arr)-1 step 4
  40. if Arr(i) <> "" then
  41. Redim preserve Arr4(p)
  42. Arr4(p) = Arr(i)
  43. p = p +1
  44. end if
  45. next
  46.  
  47. z = 0
  48. for i = 3 to ubound(Arr)-1 step 4
  49. if Arr(i) <> "" then
  50. Redim preserve Arr5(z)
  51. Arr5(z) = Arr(i)
  52. z = z +1
  53. end if
  54. next
  55.  
  56. 'conexión bd
  57.  
  58. for i = 0 to j-1
  59. SQL="UPDATE tabla SET camp1='"&Arr2(i)&"', camp2='"&Arr3(i)&"', camp3='"&Arr4(i)&"' WHERE camp4 ='"&Arr5(i)&"'"
  60. oConn.Execute(SQL)
  61. next 'i
  62.  
  63. oConn.Close
  64. set oConn = nothing
  65.  
  66. Response.Write("Todo acabó bien")
  67. %>
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />