Вы находитесь на странице: 1из 4

Public Sub EmpleadoAdicionar(ByVal vLastname As String, ByVal vFirstname As String, ByVal vTitle As String) Dim Cnx As New SqlConnection(ConfigurationManager.AppSettings.

Get("Conexion")) Dim cmd As New SqlCommand("usp_Empleado_Adicionar", Cnx) With cmd .CommandType = CommandType.StoredProcedure .Parameters.Add("@Lastname", SqlDbType.VarChar, 20).Value = vLastname .Parameters.Add("@Firstname", SqlDbType.VarChar, 10).Value = vFirstname .Parameters.Add("@Title", SqlDbType.VarChar, 50).Value = vTitle End With CREATE PROCEDURE usp_Empleado_Adicionar Try @Lastname varchar(20), Cnx.Open() @Firstname VARCHAR(10), cmd.ExecuteNonQuery() @Title varchar(50) Cnx.Close() AS Catch ex As Exception Insert into Employees(Lastname,Firstname,Title) Throw ex values(@Lastname,@Firstname,@Title) End Try End Sub Public Sub EmpleadoActualizar(ByVal vEmployeeid As Integer, ByVal vLastname As String, ByVal vFirstname As String, ByVal vTitle As String) Dim Cnx As New SqlConnection(ConfigurationManager.AppSettings.Get("Conexion")) Dim cmd As New SqlCommand("usp_Empleado_Actualizar", Cnx) With cmd .CommandType = CommandType.StoredProcedure .Parameters.Add("@Employeeid", SqlDbType.Int).Value = vEmployeeid .Parameters.Add("@Lastname", SqlDbType.VarChar, 20).Value = vLastname .Parameters.Add("@Firstname", SqlDbType.VarChar, 10).Value = vFirstname .Parameters.Add("@Title", SqlDbType.VarChar, 50).Value = vTitle End With Create PROCEDURE usp_Empleado_Actualizar Try @Employeeid int, Cnx.Open() @Lastname varchar(20), cmd.ExecuteNonQuery() @Firstname VARCHAR(10), Cnx.Close() @Title varchar(50) Catch ex As Exception AS Throw ex Update Employees set Lastname=@Lastname, End Try Firstname=@Firstname, Title=@Title End Sub Where Employeeid=@Employeeid

Public Sub EmpleadoEliminar(ByVal vEmployeeid As Integer) Dim Cnx As New SqlConnection(ConfigurationManager.AppSettings.Get("Conexion")) Dim cmd As New SqlCommand("usp_Empleado_Eliminar", Cnx) With cmd .CommandType = CommandType.StoredProcedure .Parameters.Add("@Employeeid", SqlDbType.Int).Value = vEmployeeid End With Try CREATE PROCEDURE usp_Empleado_Eliminar Cnx.Open() @Employeeid int cmd.ExecuteNonQuery() AS Cnx.Close() Delete from Employees Catch ex As Exception Where Employeeid=@Employeeid Throw ex End Try End Sub End Class

Txtcodigo , Txtapellido, Txtnombre, Txtcargo

Nos falta programar dentro de nuestro formulario DatosEmpleado.aspx

btnAdicionar, btnactualizar, btneliminar, btnnuevo

Web_Form DatosEmpleado.aspx(Formulario 2)
Imports System.Data.SqlClient Partial Class DatosEmpleado Inherits System.Web.UI.Page Private objX As New ClsEmpleado Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then Dim Codigo As String = Request.QueryString("cod") Dim dr As SqlDataReader = objX.EmpleadoDatos(Integer.Parse(Codigo)) dr.Read() txtcodigo.Text = dr(0) txtapellido.Text = dr(1) txtnombre.Text = dr(2) txtcargo.Text = dr(3) dr.Close() End If End Sub Protected Sub btnAdicionar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdicionar.Click Try objX.EmpleadoAdicionar(txtapellido.Text, txtnombre.Text, txtcargo.Text) Server.Transfer("ListaEmpleados.aspx") Catch ex As Exception lblerror.Text = ex.Message End Try End Sub

Llamar a la clase ClsEmpleado

Protected Sub btnactualizar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnactualizar.Click Try objX.EmpleadoActualizar(Integer.Parse(txtcodigo.Text), txtapellido.Text, txtnombre.Text, txtcargo.Text) Server.Transfer("ListaEmpleados.aspx") Catch ex As Exception lblerror.Text = ex.Message End Try End Sub Protected Sub btneliminar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btneliminar.Click Try objX.EmpleadoEliminar(Integer.Parse(txtcodigo.Text)) Server.Transfer("ListaEmpleados.aspx") Catch ex As Exception lblerror.Text = ex.Message End Try End Sub Protected Sub btnnuevo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnnuevo.Click txtcodigo.Text = "" txtapellido.Text = "" txtnombre.Text = "" txtcargo.Text = "" End Sub End Class

Вам также может понравиться