UNIDAD 5: INTRODUCION A LAS BASES DE DATOS

C# POCKET PDA 13: EDICION DE REGISTROS


Editar registros significa cambiar el contenido de algunos de los campos o columnas por nueva informacíón o para corregir algun error de captura original o para agregar alguna columna que no existia por modificación de la tabla o la base de datos.

PARA ESTE CASO SE USA LA INSTRUCCION SQL UPDATE (YA ESTUDIARON EL TUTORIAL DE SQL)

Prog25.aspx


<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage"

Language=CS%>

<%@ Register TagPrefix="mobile"

Namespace="System.Web.UI.MobileControls"

Assembly="System.Web.Mobile"%>

<%@ Import Namespace="System" %>

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

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

<B>EDICION</B>

<mobile:Form runat=server Paginate=true>

CLAVE EDITAR.:<mobile:TEXTBOX SIZE=3 ID=CLAVE runat=server />

<mobile:Command runat=server OnClick=BUSCAR Text=EDITAR />

NOMBRE:<mobile:TEXTBOX SIZE=10 ID=NOMBRE runat=server />

EDAD..:<mobile:TEXTBOX SIZE=3 ID=EDAD runat=server />

<mobile:Command runat=server OnClick=GRABAR Text=GRABAR />

<mobile:Label runat=server id=RESULTADO />

</mobile:Form>

<script runat=server>

// creando y cargando coneccion, adpater, dataset como variables globales

OleDbConnection coneccion;

DataSet tabla;

OleDbDataAdapter canal;

OleDbCommand orden;

string q;

void BUSCAR(Object sender, EventArgs e)

{

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

q="select * from mitabla where clave = @CLAVE";

canal=new OleDbDataAdapter(q, coneccion);

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

canal.SelectCommand.Parameters["@CLAVE"].Value = CLAVE.Text;

tabla= new DataSet();

canal.Fill(tabla, "mitabla");

int cren=tabla.Tables["mitabla"].Rows.Count;

NOMBRE.Text = tabla.Tables["mitabla"].Rows[cren-1][1].ToString();

EDAD.Text = tabla.Tables["mitabla"].Rows[cren-1][2].ToString();

// cerrando conneccion recordar que FILL NO OCUPA CERRAR

coneccion.Close();

}

void GRABAR(Object sender, EventArgs e)

{

//abriendo coneccion y COMMAND(A LO FLOJO)

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

// un problema de UPDATE de sql

q = "UPDATE mitabla SET clave= @CLAVE, nombre= @NOMBRE, edad = @EDAD where clave= @CLAVE";

orden = new OleDbCommand(q, coneccion);

// cargando y convirtiendo parametros

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

orden.Parameters["@CLAVE"].Value = Int32.Parse(CLAVE.Text);

orden.Parameters.Add(new OleDbParameter("@NOMBRE", OleDbType.VarWChar, 20));

orden.Parameters["@NOMBRE"].Value = (NOMBRE.Text).ToString();

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

orden.Parameters["@EDAD"].Value = Int32.Parse(EDAD.Text);

// mandando actualizacion a la base de datos

orden.Connection.Open();

orden.ExecuteNonQuery();

orden.Connection.Close();

//avisando operacion

RESULTADO.Text="REGISTRO ACTUALIZADO";

CLAVE.Text="";

NOMBRE.Text="";

EDAD.Text="";

}

</SCRIPT>

Solo se combinaron los programas de busqueda e inserccion pero con sql update veamos la corrida completa:

Prog25.aspx

image511.jpg

image512.jpg

image513.jpg

NOTA: A TODOS NUESTROS AMABLES VISITANTES QUE ESTEN INTERESADOS EN PLANTAR Y EJECUTAR ESTOS PROGRAMAS AQUI EN WWW.PROGRAMACIONFACIL.COM POR FAVOR HACER CLICK EN ESTE ANUNCIO IMPORTANTEpara poder abrirles una cuenta e instrucciones de uso apropiadas.

1.- construir aspx's de edición para sus tablas y bases de datos

 




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