Ver Mensaje Individual
  #2 (permalink)  
Antiguo 19/06/2002, 09:32
Avatar de TomaHawkk
TomaHawkk
 
Fecha de Ingreso: diciembre-2001
Ubicación: España
Mensajes: 422
Antigüedad: 23 años, 6 meses
Puntos: 1
Re: Modificar registros desde web

Espero que te sirva...

Código:
 
<%
Option Explicit 
%>

<html>
<head><title>ejemplo</title>

<body>

<%

IF Request.Form("Username") = "" THEN

%>

<form method="post" action="modificar1.asp">

inserte el Username del alumno ...<br>

	Username:<input name="Username">
	Nombre:<input name="Nombre"><br>
	Pais:<input name="Pais">

	<input type="submit" value="enviar">

</form>

<% 

ELSE

'Declaracion de variables
Dim Obj_Conn
Dim Obj_RS
Dim Nombre
Dim Pais
Dim Username
Dim strSQL

'Fin declaracion de variables

Nombre = Request.Form ("Nombre")
Pais = Request.Form ("Pais")
Username = Request.Form ("Username")


SET Obj_Conn = Server.CreateObject("ADODB.Connection") 

Obj_Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\db\agencias.mdb") 

'Suponiendo que la Tabla se llama ALUMNOS y el campo USERNAME, comprobamos que el alumno existe.
strSQL = "select USERNAME from ALUMNOS where USERNAME = '" & Username & "'"
SET Obj_RS = Obj_Conn.Execute(strSQL)

IF NOT Obj_RS.EOF THEN
' Usuario correcto, actualizar datos.
strSQL = "update ALUMNOS set NOMBRE = '" & Nombre & "', PAIS = '" & Pais & "' where USERNAME = '" & Username & "'"

Obj_Conn.Execute(strSQL)

response.write "<h1>Los datos del alumno se han actualizado correctamente.</h1>"

ELSE

response.write "<h1>El usuario no existe en la base de datos.</h1>"

END IF


Obj_RS.Close
Obj_Conn.Close
SET Obj_RS = Nothing
SET Obj_Conn = Nothing

END IF

%>

</body>
</html>
Saludos :)