Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/05/2002, 02:04
Nochero
 
Fecha de Ingreso: febrero-2002
Ubicación: Mi ASP Bunker
Mensajes: 397
Antigüedad: 23 años, 2 meses
Puntos: 1
Funcion para Tipicos Procesos de Tablas

Aqui les presento una funcion que realice hoy, que nos ahorrara mucho tiempo de escritura repetitiva y de depuracion, a la vez que nos dara mayor seguridad para las tipicas operaciones de tablas :

Function OP(comando,tabla,where,order,campos,valores)
Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.Recordset")
Conn.Open Session("strConn")
if where<>"" then where = " WHERE " & where
if order<>"" then order = " ORDER BY " & order

Select Case comando
Case "Agregar"
sql = "INSERT INTO " & tabla & " (" & campos & ") VALUES (" & valores & ") " & where & order

Case "Actualizar"
sql = "UPDATE " & tabla & " SET " & campos & where

Case "Agregar"
sql = "INSERT INTO " & tabla & " (" & campos & ") VALUES (" & valores & ") " & where & order

Case "Eliminar" ' No olvidarse el Where o borrara toda la tabla !
sql = "DELETE * FROM " & tabla & where

Case "Abrir","Obtener"
sql = "SELECT * FROM " & tabla & where & order
RS.CursorType = 3
RS.CursorLocation = 3
RS.Open sql, conn
if comando="Abrir" then
Set OP = RS
else
OP = Not RS.RecordCount
RS.Close
Conn.Close
end if

End Select

if comando<>"Abrir" And comando<>"Obtener" then
Conn.Execute sql,regs
OP = regs
end if

End Function