**visual

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1



    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label2.Click

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim conexion As New SqlConnection("Data Source=MIRIAM-
HPSQLEXPRESS;Initial Catalog=bd_pelicula;Integrated Security=True")
        Dim comando As New SqlCommand()
        comando.Connection = conexion
        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "calcular"
        comando.Parameters.Clear()

        Dim pel As Integer = CInt(TextBox1.Text)
        Dim ren As Integer = CInt(TextBox2.Text)
        Dim fecha As Date = DateTimePicker1.Value

        comando.Parameters.AddWithValue("@idrenta", ren)
        comando.Parameters.AddWithValue("@idpeli", pel)
        comando.Parameters.AddWithValue("@fechareal", fecha)

        conexion.Open()

        TextBox3.Text = comando.ExecuteScalar().ToString()
        conexion.Close()




    End Sub
End Class

**procedimiento

USE [bd_pelicula]
GO
/****** Object: StoredProcedure [dbo].[calcular]     Script Date: 12/03/2012
13:07:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date,,>
-- Description:   <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[calcular]
-- Add the parameters for the stored procedure here
        @idrenta as int,
        @idpeli as int,
        @fechareal as datetime


AS
BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.


        SET NOCOUNT ON;

declare @precio as money
select @precio = penalizacion from pelicula where id_pelicula = @idpeli
update pelicula set no_copias = no_copias+1 where id_pelicula= @idpeli

update Renta_detalle set fecha_real = @fechareal where id_pelicula = @idpeli and
id_renta = @idrenta

declare @diffecha as int
select @diffecha = datediff(DD, fecha_devolucion, @fechareal)from Renta_detalle
where id_renta = @idrenta

 update Renta_detalle set dias_penalizacion = @diffecha where id_pelicula =
@idpeli and id_renta = @idrenta

  update Renta_detalle set costo_penalizacion = @precio * @diffecha where
id_pelicula = @idpeli and id_renta = @idrenta

--hay que regresar un dato del procedimieto
select @precio * @diffecha as 'total'


END

**

Uni2

  • 1.
    **visual Imports System.Data Imports System.Data.SqlClient PublicClass Form1 Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conexion As New SqlConnection("Data Source=MIRIAM- HPSQLEXPRESS;Initial Catalog=bd_pelicula;Integrated Security=True") Dim comando As New SqlCommand() comando.Connection = conexion comando.CommandType = CommandType.StoredProcedure comando.CommandText = "calcular" comando.Parameters.Clear() Dim pel As Integer = CInt(TextBox1.Text) Dim ren As Integer = CInt(TextBox2.Text) Dim fecha As Date = DateTimePicker1.Value comando.Parameters.AddWithValue("@idrenta", ren) comando.Parameters.AddWithValue("@idpeli", pel) comando.Parameters.AddWithValue("@fechareal", fecha) conexion.Open() TextBox3.Text = comando.ExecuteScalar().ToString() conexion.Close() End Sub End Class **procedimiento USE [bd_pelicula] GO /****** Object: StoredProcedure [dbo].[calcular] Script Date: 12/03/2012 13:07:55 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= ALTER PROCEDURE [dbo].[calcular]
  • 2.
    -- Add theparameters for the stored procedure here @idrenta as int, @idpeli as int, @fechareal as datetime AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; declare @precio as money select @precio = penalizacion from pelicula where id_pelicula = @idpeli update pelicula set no_copias = no_copias+1 where id_pelicula= @idpeli update Renta_detalle set fecha_real = @fechareal where id_pelicula = @idpeli and id_renta = @idrenta declare @diffecha as int select @diffecha = datediff(DD, fecha_devolucion, @fechareal)from Renta_detalle where id_renta = @idrenta update Renta_detalle set dias_penalizacion = @diffecha where id_pelicula = @idpeli and id_renta = @idrenta update Renta_detalle set costo_penalizacion = @precio * @diffecha where id_pelicula = @idpeli and id_renta = @idrenta --hay que regresar un dato del procedimieto select @precio * @diffecha as 'total' END **