25 - UPDATE (Modificación de un registro de una tabla - SQL Server)


Simulador (Cuando presiona el botón "ejecutar el programa" se graban todos los cuadros de texto y se ejecuta el primero de la lista mostrando en una página el resultado)

Problema:

<html>
<head>
<title>problema</title>
</head>
<body>
<form action="pagina1.asp" method="post">
Ingrese el nombre del artículo a modificar:
<input type="text" name="nombre"><br>
<input type="submit" value="Buscar"><br>
</form>
</body>
</html>
<%option explicit%>
<html>
<head>
<title>problema</title>
</head>
<body>
<%
dim conexion
set conexion = Server.CreateObject("ADODB.Connection")
conexion.ConnectionString = "Provider=SQLOLEDB.1;" & _
			    "Data Source=.;" & _
			    "Integrated Security=SSPI;" & _
			    "Persist Security Info=False;" & _
			    "Initial Catalog=wi630629_aspya"
conexion.Open
dim registros
set registros = Server.CreateObject("ADODB.RecordSet")  
registros.open "select codigo,descripcion,precio from articulos where descripcion='" _
    & request.form("nombre") & "'" ,conexion
if not registros.eof then
%>
<form action="pagina2.asp" method="post">
Descripcion del articulo:
<input type="text" name="descripcion" size="30"
value="<%response.write(registros("descripcion"))%>"><br>
Precio:
<input type="text" name="precio" size="10"
value="<%response.write(registros("precio"))%>"><br>
<input type="hidden" name="codigo"
value="<%response.write(registros("codigo"))%>">
<input type="submit" value="Confirmar"><br>
</form>
<%
else
  response.write("No existe ningún artículo con dicho nombre")
end if
conexion.close
%>
</body>
</html>

<%option explicit%>
<html>
<head>
<title>problema</title>
</head>
<body>
<%
dim conexion
set conexion = Server.CreateObject("ADODB.Connection")
conexion.ConnectionString = "Provider=SQLOLEDB.1;" & _
			    "Data Source=.;" & _
			    "Integrated Security=SSPI;" & _
			    "Initial Catalog=wi630629_aspya"
conexion.Open
conexion.execute("update articulos set descripcion='" & _
    request.form("descripcion") & "'," & _
    "precio=" & request.form("precio") & _
    " where codigo=" & request.form("codigo"))
conexion.close
response.write("Los datos fueron modificados")
%>
</body>
</html>

Confeccionar una serie de páginas que nos permitan modificar la descripción y el precio de un artículo, para su búsqueda ingresar su descripción.


Ver solución

pagina1.html







pagina1.asp




pagina2.asp



Retornar