UNIDAD 5: VISUAL WEB DEVELOPER 2005 C# LAS BASES DE DATOS

TEMA 12: PROGRAMACION VISUAL C# BAJAS O ELIMINACION SQL DELETE

Eliminacion 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 instruccion sql a usar es:

DELETE FROM TABLA WHERE CONDICION

Y DELETE USA OBJETO COMMAND

Programa


<%@ Page Language="C#" %>

<%@ Import Namespace="System" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.OleDb" %>

<%@ Import Namespace="System.Data.SqlClient" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)

{

// objetos SQL que se ocupan

SqlConnection CANAL;

SqlCommand ORDEN;

CANAL = new SqlConnection(" Persist Security Info=True;User ID=lsoto;Password=TUPASSWORD;Initial Catalog=lsoto;Data Source=sql13.hostbasket.com");

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

ORDEN = new SqlCommand(q, CANAL);

ORDEN.Parameters.Add(new SqlParameter("@CLAVE", SqlDbType.SmallInt));

ORDEN.Parameters["@CLAVE"].Value = CLAVE.Text;

// Mandando la ORDEN

ORDEN.Connection.Open();

ORDEN.ExecuteNonQuery();

ORDEN.Connection.Close();

// Avisando

Label2.Text = "REGISTRO ELIMINADO";

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>BASES DE DATOS </title>

</head>

<body>

<form id="form1" runat="server">

<asp:Label ID="Label1" runat="server" Text="CLAVE A ELIMINAR"></asp:Label>&nbsp;&nbsp;<asp:TextBox

ID="CLAVE" runat="server" Width="46px"></asp:TextBox>

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="BAJA" /><br />

<br />

<br />

<asp:Label ID="Label2" runat="server" Text="Label" Width="52px"></asp:Label>

</form>

</body>

</html>

Corrida:

image487.jpg

TAREAS PROGRAMACION VISUAL WEB DEVELOPER 2005 C#

1.- construir este proceso para las tablas que tengan construidas y agregar este proceso a su programa de menu.

 




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