[youtube=640,360]https://www.youtube.com/watch?v=OyakeRAP5SU[/youtube]
video sql server - vb studio 2008
video sql server - vb studio 2008
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
go
use master
go
if(DB_ID('ejercicio')is not null)
drop database ejercicio
go
create database ejercicio
go
use ejercicio
go
create table producto (
idp char(3)primary key,
nombre varchar(30)not null,
procedencia varchar(20)not null check (procedencia in('Nacional','Importado')),
precio money,
presentacion varchar(15)not null check(presentacion in('Caja','Lata','Bolsa')),
stock int not null check(stock >0),
fvencimiento date)
go
create proc registrar(
@idp char(3),
@nombre varchar(30),
@proc varchar(20),
@precio money,
@presen varchar(15),
@stock int,
@fv date,
@msj varchar(60)output)
as begin
if(exists(select * from producto where idp =@idp ))
set @msj ='el id '+','+@idp +'Producto ya existe'
else begin
insert producto values(@idp ,@nombre ,@proc ,@precio ,@presen ,@stock ,@fv )
set @msj ='DATOS REGISTRADOS'
end
end
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Public con As New SqlConnection("Server=.;DataBase=ejercicio;Integrated Security=true")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cbxpresentacion.Items.Add("Seleccione") : cbxpresentacion.Items.Add("Caja")
cbxpresentacion.Items.Add("Lata") : cbxpresentacion.Items.Add("Bolsa")
rbtnacional.Checked = True
cbxpresentacion.SelectedIndex = 0
'para validar meses
vermes()
End Sub
Sub abrir()
If con.State = 0 Then con.Open()
End Sub
Sub cerrar()
If con.State = 1 Then con.Close()
End Sub
Private Sub btnregistrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnregistrar.Click
If txtcodigo.Text <> "" And txtnombre.Text <> "" And txtprecio.Text <> "" And txtstock.Text <> "" Then
If cbxpresentacion.SelectedIndex <> 0 Then
Try
Dim cmd As New SqlCommand
Dim msje As String = ""
abrir()
cmd = New SqlCommand("registrar", con)
cmd.CommandType = 4
With cmd.Parameters
.AddWithValue("@idp", txtcodigo.Text)
.AddWithValue("@nombre", txtnombre.Text)
If rbtnacional.Checked = True Then
.AddWithValue("@proc", "Nacional")
Else
.AddWithValue("@proc", "Importado")
End If
.AddWithValue("@precio", txtprecio.Text)
.AddWithValue("@presen", cbxpresentacion.Text)
.AddWithValue("@stock", txtstock.Text)
.AddWithValue("@fv", datefv.Value)
.Add("@msj", SqlDbType.VarChar, 60).Direction = 2
cmd.ExecuteNonQuery()
msje = cmd.Parameters("@msj").Value
MessageBox.Show(msje)
limpiar()
End With
Catch ex As Exception
End Try
cerrar()
Else
MessageBox.Show("Seleccione Un Indice del Combo")
End If
Else
MessageBox.Show("Llene Cajas")
End If
End Sub
Sub limpiar()
txtcodigo.Clear() : txtnombre.Clear() : txtprecio.Clear()
txtstock.Clear()
rbtnacional.Checked = True
cbxpresentacion.SelectedIndex = 0
End Sub
Sub vermes()
',con esto al momento de escoger el valor del datetimepicker
'el mes se suma 2
Dim mes As Integer = Now.Month
datefv.MinDate = New DateTime(Now.Year, mes + 2, Now.Day)
End Sub
Private Sub datefv_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles datefv.ValueChanged
vermes()
End Sub
End Class
go
use master
go
if(DB_ID('parcialvidarteDelgad')is not null)
drop database parcialvidarteDelgad
go
create database parcialvidarteDelgad
go
use parcialvidarteDelgad
go
create table tipopelicula(
tipo varchar(14)primary key
)
go
insert tipopelicula values ('DRAMA')
insert tipopelicula values ('Suspenso')
insert tipopelicula values ('Terror')
insert tipopelicula values ('CienciaFiccion')
insert tipopelicula values ('Otros')
go
create table pelicula(
id int identity primary key,
nombre varchar(30)unique,
tipo varchar(14)foreign key references tipopelicula,
añof date,
stock int
)
go
create proc listartipo(@tipo varchar(30))
as begin
select * from pelicula where tipo =@tipo
end
go
create proc registrar(@n varchar(30),@tipo varchar(14),@añof date,@stock int,@msj varchar(60)output)
as begin
if (exists(select * from pelicula where nombre =@n ))
set @msj ='Ya existe pelicula'
else
begin
insert into pelicula values(@n ,@tipo ,@añof ,@stock )
set @msj ='OK'
end
end
GO
create proc MODIFICAR(@id int,@n varchar(30),@tipo varchar(14),@añof date,@stock int,@msj varchar(60)output)
as begin
if (NOT exists(select * from pelicula where id =@id ))
set @msj ='no existe pelicula'
else
begin
update pelicula set nombre =@n ,tipo =@tipo ,añof=@añof ,stock =@stock where id =@id
set @msj ='OK'
end
end
go
create proc buscar(@id int)
as begin
select * from pelicula where id =@id
end
go
insert into pelicula values('Odisea','DRAMA','10/10/2010',18)
go
Imports System.Data
Imports System.Data.SqlClient
Partial Class pagina1
Inherits System.Web.UI.Page
Private con As New SqlConnection("Server=.;DataBase=parcialvidarteDelgad;Integrated Security=true")
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim cmd As New SqlCommand
Dim msj As String = ""
Try
abrir()
cmd = New SqlCommand("registrar", con)
cmd.CommandType = 4
With cmd.Parameters
.AddWithValue("@n", txtn.Text)
.AddWithValue("@tipo", cbxtipo.SelectedValue)
.AddWithValue("@añof", CDate(txtaño.Text))
.AddWithValue("@stock", CInt(txtstock.Text))
.Add("@msj", SqlDbType.VarChar, 60).Direction = 2
End With
cmd.ExecuteNonQuery()
msj = cmd.Parameters("@msj").Value
MsgBox(msj)
Catch ex As Exception
MsgBox(ex.Message)
End Try
cerrar()
limpiar()
End Sub
Sub limpiar()
txtaño.Text = ""
txtid.Text = ""
txtn.Text = ""
txtstock.Text = ""
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
listartipos()
End If
End Sub
Sub listartipos()
Dim dt As New DataTable
Dim da As SqlDataAdapter
Try
abrir()
da = New SqlDataAdapter("select * from tipopelicula", con)
da.Fill(dt)
cbxtipo.DataValueField = "tipo"
cbxtipo.DataTextField = "tipo"
cbxtipo.DataSource = dt
cbxtipo.DataBind()
Catch ex As Exception
MsgBox(ex.Message)
End Try
cerrar()
End Sub
Sub abrir()
If con.State = 0 Then con.Open()
End Sub
Sub cerrar()
If con.State = 1 Then con.Close()
End Sub
Protected Sub cbxtipo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbxtipo.SelectedIndexChanged
Dim dt As New DataTable
Dim da As SqlDataAdapter
Try
abrir()
da = New SqlDataAdapter("listartipo", con)
da.SelectCommand.CommandType = 4
da.SelectCommand.Parameters.AddWithValue("@tipo", cbxtipo.SelectedValue)
da.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
Catch ex As Exception
MsgBox(ex.Message)
End Try
cerrar()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim dt As New DataTable
Dim da As SqlDataAdapter
Try
abrir()
da = New SqlDataAdapter("buscar", con)
da.SelectCommand.CommandType = 4
da.SelectCommand.Parameters.AddWithValue("@id", txtid.Text)
da.Fill(dt)
txtid.Text = dt.Rows(0).Item(0).ToString
txtn.Text = dt.Rows(0).Item(1).ToString
cbxtipo.Text = dt.Rows(0).Item(2).ToString
txtaño.Text = dt.Rows(0).Item(3).ToString
txtstock.Text = dt.Rows(0).Item(4).ToString
Catch ex As Exception
MsgBox(ex.Message)
End Try
cerrar()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As New SqlCommand
Dim msj As String = ""
Try
abrir()
cmd = New SqlCommand("MODIFICAR", con)
cmd.CommandType = 4
With cmd.Parameters
.AddWithValue("@id", txtid.Text)
.AddWithValue("@n", txtn.Text)
.AddWithValue("@tipo", cbxtipo.SelectedValue)
.AddWithValue("@añof", CDate(txtaño.Text))
.AddWithValue("@stock", CInt(txtstock.Text))
.Add("@msj", SqlDbType.VarChar, 60).Direction = 2
End With
cmd.ExecuteNonQuery()
msj = cmd.Parameters("@msj").Value
MsgBox(msj)
Catch ex As Exception
MsgBox(ex.Message)
End Try
cerrar()
limpiar()
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
limpiar()
End Sub
End Class