Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/04/2009, 15:43
Avatar de JuanRAPerez
JuanRAPerez
Colaborador
 
Fecha de Ingreso: octubre-2003
Mensajes: 2.393
Antigüedad: 21 años, 6 meses
Puntos: 27
Respuesta: Problema al insertar en una tabla

me parece que ha había leído algo sobre este tema (creo que estas duplicando post)

Tu codigo (al leerlo rápido dice)

+ SI la variable num_serie3_1 viene vacia
+ Muéstreme el formulario
+ recoger las variables
+ inserte las variables en blanco
+ listo

por eso asocio te inserta el registro en blanco al entrar a la pagina porque a ley esta insertado el valor en blanco

ummm mi idea seria:

Código ASP:
Ver original
  1. <%
  2. if num_serie3_1 = "" then
  3. %>
  4.  
  5. <form method="Post" action="agregacelular.asp">
  6.  
  7. <table width="308" border="2" align="center" cellpadding="1" cellspacing="0" name="tabla">
  8.   <tr><td colspan=2 align="center" class="Estilo5">Agregar Nuevo CELULAR</td>
  9.   </tr>
  10.   <tr><td colspan="2" height=5></td></tr>
  11.      
  12.    <tr>
  13.       <td width="38%" nowrap class="Estilo4">N&uacute;mero de Serie:</td>
  14.       <td colspan="2">
  15.             <input name ="text1"  size="25" maxlength="15"><BR>
  16.       </td>
  17.    </tr>
  18.    
  19.    <tr>
  20.       <td width="38%" nowrap class="Estilo4">Equipo:</td>
  21.       <td colspan="2">
  22.             <input name="text2" size="25" maxlength="20"><BR>
  23.       </td>
  24.    </tr>
  25.    
  26.    <tr>
  27.       <td width="38%" nowrap class="Estilo4">Modelo:</td>
  28.       <td colspan="2">
  29.             <input name="text3" size="25" maxlength="10"><BR>
  30.       </td>            
  31.    </tr>
  32.    
  33.    <tr>
  34.       <td width="38%" nowrap class="Estilo4">Mac:</td>
  35.       <td colspan="2">
  36.             <input name="tetx4" size="25" maxlength="17"><BR>
  37.       </td>
  38.    </tr>
  39.    
  40.    <tr>
  41.       <td width="38%" nowrap class="Estilo4">Pin:</td>
  42.       <td colspan="2">
  43.             <input name="text5" size="25" maxlength="8"><BR>
  44.       </td>
  45.    </tr>
  46.            
  47.    <tr>
  48.       <td width="38%"  nowrap class="Estilo4">Accesorios</td>
  49.       <td colspan="2">
  50.             <input name="text6" size="25" maxlength="200"><BR>
  51.       </td>
  52.    </tr>
  53.                      
  54.    <tr>
  55.       <td width="38%" nowrap class="Estilo4">Fecha Entrega Celular</td>
  56.       <td colspan="2">
  57.             <input name="text7" size="25" maxlength="10"><BR>
  58.       </td>
  59.    </tr>
  60.            
  61.    <tr>
  62.       <td width="38%" nowrap class="Estilo4">Fecha Retiro Celular</td>
  63.       <td colspan="2">
  64.             <input name="text8" size="25" maxlength="10"><BR>
  65.       </td>
  66.    </tr>
  67.            
  68.    <tr>
  69.       <td width="38%" nowrap class="Estilo4">Asigando</td>
  70.       <td colspan="2">
  71.             <input name="text9" size="25" maxlength="50"><BR>
  72.       </td>
  73.    </tr>
  74.    
  75.    <tr>
  76.       <td width="38%" nowrap class="Estilo4">No Asignado</td>
  77.       <td colspan="2">
  78.             <input name="text10" size="25" maxlength="50"><BR>
  79.       </td>
  80.    </tr>
  81.                                            
  82.    <tr>
  83.       <td width="38%" nowrap class="Estilo4">Notas</td>
  84.       <td colspan="2">
  85.             <input name="text11" size="25" maxlength="200"><BR>
  86.       </td>
  87.    </tr>
  88.                
  89.   <tr>
  90.       <td colspan="6" align="center">
  91.           <input type="Submit" value="&nbsp;&nbsp;Agregar&nbsp;&nbsp;" onClick="return window.confirm('Desea Ingresar el registro')">
  92.       </td>
  93.       <td width="13%"></td>
  94.   </tr>    
  95. </table>  
  96. <%
  97. else
  98. %>
  99. <%
  100.   num_serie3_1 = request.Form("text1")
  101.   equipo3_1 = request.Form("text2")
  102.   modelo3_1 = request.Form("text3")
  103.   mac3_1 = request.Form("text4")
  104.   pin3_1 = request.Form("text5")
  105.   accesorios3_1 = request.Form("text6")
  106.   fecha_entrega_celular3_1 = request.Form("text7")
  107.   fecha_retiro_celular3_1 = request.Form("text8")
  108.   asignado3_1 = request.Form("text9")
  109.   no_asignado3_1 = request.Form("text10")
  110.   notas3_1 = request.Form("text11")
  111.  
  112.   SQL3_1 = "INSERT INTO CELULAR (NUM_SERIE, EQUIPO, MODELO, MAC, PIN, ACCESORIOS, FECHA_ENTREGA_CELULAR, FECHA_RETIRO_CELULAR, ASIGNADO, NO_ASIGNADO, NOTAS) VALUES " &  "('" & num_serie3_1 & "', '" & equipo3_1 & "', '" & modelo3_1 & "', '" & mac3_1 & "', '" & pin3_1 & "', '" & accesorios3_1 & "', '" & fecha_entrega_celular3_1 & "', '" & fecha_retiro_celular3_1 & "', '" & asignado3_1 & "', '" & no_asignado & "', '" & notas3_1 & "')"
  113.  
  114.   set obj_conn3_1=server.createobject("ADODB.connection")
  115.       obj_conn3_1.open "PRUEBA"
  116.       obj_conn3_1.execute sql3_1
  117.       obj_conn3_1.Close
  118.       set obj_conn3_1 = Nothing
  119. %>
  120. </form>
  121. <%
  122. End if
  123. %>

linea 97, 98, 99 adicione

consejo

+ busca ayuda sobre on error resume next para que le mande un error mas descriptivo al usuario
+ al final después de insertado dile al usuario "en hora buena has insertado correctamente un registro
+ coloca un enlace que diga "insertar otro?????"

suerte
__________________
JuanRa Pérez
San Salvador, El Salvador