C# CGI UNIDAD 5: INTRODUCION A LAS BASES DE DATOS

TEMA 12: BAJA O ELIMINACION


Eliminación es otro proceso simple y comun con las bases de datos el modelo con ADO.NET que estamos usando hace este tipo de operaciones muy faciles:

La instrucción sql a usar es: DELETE FROM TABLA WHERE CONDICION

Prog23.html


<HTML>

<FORM ACTION=/cgi-bin/tusitio/prog23.exe METHOD=get>

CLAVE ANIMALITO A ELIMINAR:<INPUT TYPE=text NAME=CLAVE><BR>

<INPUT TYPE=submit VALUE=ELIMINAR>

</FORM></HTML>

prog23.cs


using System;

using System.Data;

using System.Data.OleDb;

public class prog23

{

// creando y cargando coneccion

static OleDbConnection coneccion;

public static void Main()

{

lnet capturar=new lnet();

string clave= capturar.getparametro("CLAVE");

coneccion=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\progfacil\\tusitio\\mibase.mdb");

// instruccion sql DELETE FROM TABLA WHERE CLAVE=DATO

string q="delete from mitabla where clave=@CLAVE";

OleDbCommand orden= new OleDbCommand(q, coneccion);

orden.Parameters.Add(new OleDbParameter("@CLAVE", OleDbType.Integer));

orden.Parameters["@CLAVE"].Value = clave;

orden.Connection.Open();

orden.ExecuteNonQuery();

orden.Connection.Close();

// avisando

System.Console.WriteLine("Content-Type:text/html\n");

System.Console.WriteLine("<HTML>ya murio usar prog18.html para desplegar</HTML>");

// cerrando todo

coneccion.Close();

} }

OBSERVAR QUE NO SE OCUPO NI ADAPTER NI DATASET, SOLO UN COMMAND DIRECTO A LA CONECCION O BASE DE DATOS, es decir es valido mandar instrucciones sql directo a una base de datos, interesante verdad???

Corridas :

Prog18 ←-tabla original

image320.jpg

prog23.html

image321.jpg

prog23.cs o exe

image322.jpg

prog18.exe ← como queda ahora la tabla??

image323.jpg

bye, bye pobre gatito

problemas programacion sugeridos:

1.- construir este proceso para las tablas y bases de datos que tengan construidas.

 




Google
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Politica de Privacidad