Como puedo insertar mas de 5 registros en una BD alo mismo tiempo es decir desde un mismo formulario...
Atte. BatusaiX
| |||
aHHHH ![]() ![]() ![]() con un solo insert puedes insertar un tanate de cosas, ejem sSQL = sSQL & "INSERT INTO Auctions (ItemOwner, ItemTitle, CategoryID, Ended, EmailsSent) VALUES ( SQLVal(valRS.Fields("ID")) & , SQLStr(sTitle) & "SQLVAl(iCat) & " false , yes) Entend[i tu pregunta? ![]() |
| |||
aqui te mando algo que hace lo qeu quieres pero no recuerdo mucho ANALIZALO QUE NO RECUERDO BIEN LA LOGICA HACE TIEMPO LO HICE CON UN AMIGO, HABER SI ALGUIEN MAS AYUDA, EN ESTA PARTE GRABO UNA SELECCION PARECIDA CUANDO SALE LA RELACION DE EMAILS QUE TIENES Y HACES CHECK EN CADA UNO PARA BORRARLOS, EN ESTE CASO SE SELECCIONA PARA GRABAR LOS COMPONENTES DE CADA COMPUTADORA. <%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY background="images/fondo.gif" topmargin="0"> <font color="#0000FF"><b>BIEN</b></font><br> <%'Response.Write(session("wwbien")) %><br>COMPONENTES ASOCIADOS: <% dim wsql dim rs 'Recorre todas las filas del resultado %> <% dim x() INDICE=0 FOR each dato in Request.Form INDICE=INDICE+1 REDIM PRESERVE X(INDICE)%> <%if dato<>"asociar" then %> <%=dato%>:<%=Request.Form(dato).ITEM %><br> <% x(indice)=dato end if %> <%next %> <% 'grabar asociacion FOR I=1 TO UBound(x) 'Response.Write(x(i)) %><br> <%sql="insert into detalle_componente values("& x(i) &","& session("wwbien") &")" Set rs = DBbien.execute(sql) next %> <% 'Actualizar Componente asociado FOR I=1 TO UBound(x) sql="update comp_registrados set asociado_si_no='1' where cod_comp="& x(i) &"" Set rs = DBbien.execute(sql) next 'Set rs = Nothing 'cnn.Close 'Set cnn = Nothing%> <table width=100% border=0> <tr> <td> <center><h3>Componentes asociados exitosamente<h3></center> </td> </tr> <tr> <td>CODIGO DE EQUIPO DE COMPUTO ASOCIADO: </td> <td> <%=session("wwbien")%> </td> </tr> <tr> <td><CENTER>COMPONENTES ASOCIADOS CORRECTAMENTE </CENTER> </td> <td> <%=session("wwbien")%> </td> </tr> <tr> <td> <a href="asociar.asp?wbien=<%=session("wwbien")%>"><i mg border="0" src="images/regresar.gif" WIDTH="100" HEIGHT="30"> </a> </td> </tr> </table> </BODY>
__________________ Alberto |
| ||||
una cosa para que usas la funcion " i " ahi no la entiendo y otra puedo hacer eso con recordset no suelo usar mucho sql como hago que sea para 5 las pongo simplemente al lado las sentencia con que caracter las separo !! ![]() Atte.Batusai X |
| |||
Basicamente el truco esta en dim x() INDICE=0 FOR each dato in Request.Form INDICE=INDICE+1 REDIM PRESERVE X(INDICE)%> <%if dato<>"asociar" then %> <%=dato%>:<%=Request.Form(dato).ITEM %><br> <% x(indice)=dato end if %> <%next %> <% 'grabar asociacion FOR I=1 TO UBound(x) 'Response.Write(x(i)) %><br> <%sql="insert into detalle_componente values("& x(i) &","& session("wwbien") &")" Set rs = DBbien.execute(sql) next nota: la variable dato, me parece q es parte de la instruccion for each, salvo que me equivoco si alguien se acuerda.....
__________________ Alberto |
| |||
sip aqui puedes usar el recordset sql="insert into detalle_componente values("& x(i) &","& session("wwbien") &")" Set rs = DBbien.execute(sql) por: mas o menos algo asi... rs.addnew rs("campo1")= x(i) rs("campo2")= request.form("apellidos")) etc. rs.update ah, i es un contador del for, para llevar la cuenta de registros que recibe del formulario enviado, luego la pagina que procesa este formulario tiene el codigo que he indicado. mira lo voy aanalizar mejor mañana, y te digo...ahora tngo q salir.
__________________ Alberto |
| ||||
amigo. tuve que hacer algo parecido creando variables dinamicas. revisa este post que fue lo que yo hice y me resulto a la perfeccion gracias a la ayuda de este foro. ![]() http://www.forosdelweb.com/showthrea...hreadid=109011 suerte ![]() ![]() ![]() |
| ||||
Eso es lo que tengo hasta ahora pero me esta dando error en la linea del primer Request es decir en la variable "codigo" no en realidad lo que pasa pero no esta introduciendo la informacion... AYUDA !!! Formulario de Envio ====================================== <%@ LANGUAGE=VBSCRIPT %> <% Option Explicit %> <html> <head> <title>Insertar Lista de Bodas</title> </head> <body> <!--#include file="conn.asp"--> <% Dim rs, strQuery Set rs= Server.Createobject("ADODB.Recordset") rs.CursorType = 1 rs.LockType = 3 strQuery = "SELECT id FROM novios WHERE id = id " Set rs = Conn.Execute(strQuery) %> <form method="POST" action="insertar_listabodaproceso.asp"> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="36%" id="AutoNumber3"> <tr> <td width="100%"> <p align="center"><font face="Tahoma"><b><font size="2">Lista de boda #</font></b><font size="1"> <SELECT NAME="id"> <% Do While Not rs.EOF Response.Write "<OPTION VALUE='" & rs("id") & "'>" Response.Write rs("id") rs.MoveNext Loop %> </SELECT> </font></font><font size="1" face="Tahoma"><br> <br> </font></td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="349" id="AutoNumber1" height="51"> <tr> <td width="18" align="center" bordercolor="#000000" bgcolor="#000000" height="19"> <b><font color="#FFFFFF" size="1" face="Tahoma">#</font></b></td> <td width="56" align="center" bordercolor="#000000" bgcolor="#000000" height="19"> <b><font color="#FFFFFF" size="1" face="Tahoma">Código</font></b></td> <td width="204" align="center" bordercolor="#000000" bgcolor="#000000" height="19"> <b><font color="#FFFFFF" size="1" face="Tahoma">Producto</font></b></td> <td width="66" align="center" bordercolor="#000000" bgcolor="#000000" height="19"> <b><font color="#00FF00" size="1" face="Tahoma">$ Precio</font></b></td> </tr> <tr> <td width="18" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma">1.</font></td> <td width="56" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"><input type="text" name="codigo1" size="6"></font></td> <td width="204" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"> <input type="text" name="producto1" size="28"></font></td> <td width="66" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font color="#FF0000" size="1" face="Tahoma"> <input type="text" name="precio1" size="6"></font></td> </tr> <tr> <td width="18" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma">2. </font></td> <td width="56" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"><input type="text" name="codigo2" size="6"></font></td> <td width="204" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"> <input type="text" name="producto2" size="28"></font></td> <td width="66" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font color="#FF0000" face="Tahoma" size="1"> <input type="text" name="precio2" size="6"></font></td> </tr> <tr> <td width="18" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font face="Tahoma" size="1">3.</font></td> <td width="56" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"><input type="text" name="codigo3" size="6"></font></td> <td width="204" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"> <input type="text" name="producto3" size="28"></font></td> <td width="66" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font color="#FF0000" size="1" face="Tahoma"> <input type="text" name="precio3" size="6"></font></td> </tr> <tr> <td width="18" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font face="Tahoma" size="1">4.</font></td> <td width="56" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"><input type="text" name="codigo4" size="6"></font></td> <td width="204" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"> <input type="text" name="producto4" size="28"></font></td> <td width="66" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font color="#FF0000" size="1" face="Tahoma"> <input type="text" name="precio4" size="6"></font></td> </tr> <tr> <td width="18" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font face="Tahoma" size="1">5.</font></td> <td width="56" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"><input type="text" name="codigo5" size="6"></font></td> <td width="204" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font size="1" face="Tahoma"> <input type="text" name="producto5" size="28"></font></td> <td width="66" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="31"> <font color="#FF0000" size="1" face="Tahoma"> <input type="text" name="precio5" size="6"></font></td> </tr> </table> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="35%" id="AutoNumber2"> <tr> <td width="100%"> <p align="center"><br> <input type="submit" value="Insertar" name="B1"> <input type="reset" value="Borrar" name="B2"></td> </tr> </table> </form> </body> =========================================== Pagina de Proceso =========================================== <%@ LANGUAGE=VBSCRIPT %> <% Option Explicit %> <% Dim codigo(4) Dim producto(4) Dim precio(4) Dim id_tblproductos Dim i %> <!--#include file="conn.asp"--> <% Dim rs, SQL Set rs= Server.Createobject("ADODB.Recordset") rs.CursorType = 1 rs.LockType = 3 For i = 1 to 5 id_tblproductos = request.form("id") codigo= request.form("codigo" & i) producto= request.form("producto" & i) precio= request.form("precio" & i) SQL = "INSERT INTO productos (idnovios_tblp ,codigoproducto, producto, precioventa) VALUES ('"&id_tblproductos&"', '"&codigo&"','"&producto&"','"&precio&"')" rs.open SQL, Conn Next %> ============================================== |