Foros del Web » Programando para Internet » ASP Clásico »

problema con Insert y hacer calculo

Estas en el tema de problema con Insert y hacer calculo en el foro de ASP Clásico en Foros del Web. Hola Tengo un problema, y recurro a uds para pedir su valiosa ayuda. LA situacion es: Tengo 1 formulario que inserta valores(numeros) a la BD ...
  #1 (permalink)  
Antiguo 21/05/2004, 09:47
Avatar de cookie  
Fecha de Ingreso: agosto-2002
Mensajes: 688
Antigüedad: 22 años, 8 meses
Puntos: 0
Exclamación problema con Insert y hacer calculo

Hola

Tengo un problema, y recurro a uds para pedir su valiosa ayuda.

LA situacion es: Tengo 1 formulario que inserta valores(numeros) a la BD ... los campos q uso son PS,CM, EX,CS, BL,Agente(text) y result

El campo Result lo tengo como HIDDEN, esto es porque requiero que cuando se envie la informacion a la BD este campo sea llenado con el resultado de la siguiente formula que usa los demas datos.

la formula es
(PS-CM)-(EX+CS) + BL


Si se dan cuenta son solo sumas y restas, pero el detalle es que no se como hacerlo , por lo que les pido ayuda.

Me podrian ayudar como modificar el siguiente código?? .. ya inserta todo (excepto result)

Gracias de antemano

__________________

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/miconexion.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

MM_editConnection = MM_miconexion_STRING
MM_editTable = "DB.values"
MM_editRedirectUrl = ""
MM_fieldsStr = "PS|value|CM|value|EX|value|CS|value|BL|value|agen te|value|resultado|value"
MM_columnsStr = "PS|none,none,NULL|CM|none,none,NULL|EX|none,none, NULL|CS|none,none,NULL|BL|none,none,NULL|agente|no ne,none,NULL|resultado|none,none,NULL"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>


<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<form method="post" action="<%=MM_editAction%>" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">PS:</td>
<td>
<input type="text" name="PS" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CM:</td>
<td>
<input type="text" name="CM" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">EX:</td>
<td>
<input type="text" name="EX" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CS:</td>
<td>
<input type="text" name="CS" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">BL:</td>
<td>
<input type="text" name="BL" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Agente:</td>
<td>
<select name="agente">
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td>
<input type="submit" value="Insert record">
</td>
</tr>
</table>
<input type="hidden" name="resultado" value="" size="32">
<input type="hidden" name="MM_insert" value="form1">
</form>

<p>&nbsp;</p>
</body>
</html>
__________________
___________________________

do the evolution ¡
Mineriaenlinea.com

Última edición por cookie; 21/05/2004 a las 09:56
  #2 (permalink)  
Antiguo 21/05/2004, 10:03
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 23 años, 3 meses
Puntos: 146
No entiendo muy bien, pero tal vez con algo así se arregle:

vPS=SInt(Request("PS"))
vCM=SInt(Request("CM"))
vEX=SInt(Request("EX"))
vCS=SInt(Request("CS"))
vBL=SInt(Request("BL"))
Suma = (vPS-vCM)-(vEX+vCS) + vBL
MM_editQuery = "insert into " & MM_editTable & " (PS,CM, EX,CS, BL,Agente, result
) values (" & vPS & ","&vCM & ","&vEX & ","&vCS& ","&vBL& ","&request("Agente")& ","&suma& ","&")"

O algo así.
  #3 (permalink)  
Antiguo 21/05/2004, 10:09
Avatar de cookie  
Fecha de Ingreso: agosto-2002
Mensajes: 688
Antigüedad: 22 años, 8 meses
Puntos: 0
muchas gracias por contestar,

donde pondrias ese codigo que propones, de verdad soy super principiante , y esto q pongo lo hice con la granb ayuda del Dreamweaver
__________________
___________________________

do the evolution ¡
Mineriaenlinea.com
  #4 (permalink)  
Antiguo 21/05/2004, 10:37
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 23 años, 3 meses
Puntos: 146
Se nota la intromisión de Dreamweaver por lo rebuscado del código y por el exceso de MM_

La linea que propongo es para sustituir la que dice:
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

Pero la verdad es que si realmente deseas hacer un código que su mantenimiento sea fácil, te recomiendo hacerlo tu el código ASP.
Pero cada quien su estilo, jeje.

La idea es que en el insert se haga la suma al tiempo que se insertan los datos.
  #5 (permalink)  
Antiguo 21/05/2004, 11:22
Avatar de AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 24 años, 2 meses
Puntos: 535
creo que se podría modificar así:


vPS=SInt(Request("PS"))
vCM=SInt(Request("CM"))
vEX=SInt(Request("EX"))
vCS=SInt(Request("CS"))
vBL=SInt(Request("BL"))
Suma = (vPS-vCM)-(vEX+vCS) + vBL


MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ", campo_suma) values (" & MM_dbValues & ", " & Suma & ")"


(asumo que el campo donde se gurdará la variable 'Suma' es numérico y se llama "campo_suma")
__________________
...___...

Última edición por AlZuwaga; 21/05/2004 a las 11:24
  #6 (permalink)  
Antiguo 25/05/2004, 19:14
Avatar de cookie  
Fecha de Ingreso: agosto-2002
Mensajes: 688
Antigüedad: 22 años, 8 meses
Puntos: 0
lo intentare.

Gracias por sus respuestas

saludos ¡
__________________
___________________________

do the evolution ¡
Mineriaenlinea.com
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:32.