[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('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
go
use master
go
if(db_id('practicando')is not null)
drop database practicando
go
create database practicando
go
use practicando
go
create table docente(
dni char(8)primary key,
n varchar(30)not null,
ape varchar(30)not null,
sexo char(1)not null check(sexo='M'or sexo='F'),
edad tinyint)
go
create proc registrar(@dni char(8),@n varchar(30),@ape varchar(30),
@sexo char(1),@edad tinyint,@msj varchar(60)output)
as begin
if(exists(select * from docente where dni=dni ))
set @msj ='dni ya existe'
ELSE
BEGIN
insert into docente values(@dni ,@n ,@ape ,@sexo ,@edad )
set @msj ='REGISTRADO OK'
END
end
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private con As New SqlConnection("Server=.;DataBase=practicando;Integrated Security=true")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
rbtm.Checked = True
listar()
txtregistros.Text = DataGridView1.Rows.Count - 1
lblhora.Text = TimeOfDay
End Sub
Sub listar()
Dim dt As New DataTable
Dim da As SqlDataAdapter
Try
abrir()
da = New SqlDataAdapter("select * from docente", con)
da.Fill(dt)
DataGridView1.DataSource = dt
Catch ex As Exception : MsgBox(ex.Message)
End Try
cerrar()
txtregistros.Text = DataGridView1.Rows.Count - 1
End Sub
Sub abrir()
If con.State = 0 Then con.Open()
End Sub
Sub cerrar()
If con.State = 1 Then con.Close()
End Sub
Sub limpiar()
txtape.Clear()
TXTDNI.Clear()
txtedad.Clear()
txtnom.Clear()
rbtm.Checked = True
End Sub
Private Sub btnregistrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnregistrar.Click
Dim cmd As SqlCommand
Dim msj As String = ""
Try
abrir()
cmd = New SqlCommand("registrar", con)
cmd.CommandType = 4
With cmd.Parameters
.AddWithValue("@dni", TXTDNI.Text)
.AddWithValue("@n", txtnom.Text)
.AddWithValue("@ape", txtape.Text)
If rbtm.Checked = True Then
.AddWithValue("@sexo", "M")
Else
.AddWithValue("@sexo", "F")
End If
.AddWithValue("@edad", txtedad.Text)
.Add("@msj", SqlDbType.VarChar, 60).Direction = 2
End With
cmd.ExecuteNonQuery()
msj = cmd.Parameters("@msj").Value
MessageBox.Show(msj)
Catch ex As Exception : MessageBox.Show(ex.Message)
End Try
cerrar()
limpiar()
listar()
End Sub
End Class
Public Class Form1
Private mouseOffset As Point
Private isMouseDown As Boolean = False
Button1_Click(boton)
Me.Close()
'cierra el formulario
End Sub
Evento MouseDown
Dim xOffset As Integer
Dim yOffset As Integer
If e.Button = MouseButtons.Left Then
xOffset = -e.X - SystemInformation.FrameBorderSize.Width
yOffset = -e.Y - SystemInformation.CaptionHeight - _
SystemInformation.FrameBorderSize.Height
mouseOffset = New Point(xOffset, yOffset)
isMouseDown = True
End If
End Sub
Evento MouseMove
If isMouseDown Then
Dim mousePos As Point = Control.MousePosition
mousePos.Offset(mouseOffset.X, mouseOffset.Y)
Location = mousePos
End If
End Sub
Evento MouseUp del formulario
If e.Button = MouseButtons.Left Then
isMouseDown = False
End If
End Sub
Protected Overrides Sub OnPaint( _
ByVal e As System.Windows.Forms.PaintEventArgs)
Dim shape As New System.Drawing.Drawing2D.GraphicsPath
shape.AddEllipse(0, 0, Me.Width, Me.Height)
Me.Region = New System.Drawing.Region(shape)
End Sub
End Class
Public Class frmsuma
'declaramos variables privadas
Private m As Integer(,)
Private m2 As Integer(,)
Private m3 As Integer(,)
Button1
ReDim m(2, 2) 'redimensionamos una matriz de 3*3
ReDim m2(2, 2)
ReDim m3(2, 2)
Dim fil, col As Integer
Dim r As New Random
'generamos la matriz
For fil = 0 To 2
For col = 0 To 2
m(fil, col) = r.Next(10, 15)
m2(fil, col) = r.Next(5, 20)
Next
Next
'mostramos la matriz en el listview
lvw1.Items.Clear() 'clear para q limpie la lista cada ves q generamos
lvw2.Items.Clear() 'clear para q limpie la lista cada ves q generamos
lvw3.Items.Clear() 'clear para q limpie la lista cada ves q generamos
For fil = 0 To 2
lvw1.Items.Add(m(fil, 0))
lvw2.Items.Add(m2(fil, 0))
For col = 0 To 2
lvw1.Items(fil).SubItems.Add(m(fil, col))
lvw2.Items(fil).SubItems.Add(m(fil, col))
Next
Next
lvw3.Items.Clear()
End Sub
==aki code del btnsm
Dim fil, col As Integer
For fil = 0 To 2
For col = 0 To 2
m3(fil, col) = m(fil, col) + m2(fil, col)
Next
Next
lvw3.Items.Clear()
For fil = 0 To 2
lvw3.Items.Add(m3(fil, 0))
For col = 0 To 2
lvw3.Items(fil).SubItems.Add(m3(fil, col))
Next
Next
End Class
go
use master
go
if (DB_ID('tienda')is not null)
drop database tienda
go
create database tienda
go
use tienda
go
sp_helpdb tienda
go
create table users
(dni char(8)primary key,
clave varchar(8)not null,
ape varchar(30)not null,
nom varchar(30)not null)
go
--------------------procedimiento loguear
create proc loguear(@dni char(8),@clave varchar(8),@datos varchar(62)output)
as begin
if(exists(select * from users where dni=@dni and clave=@clave ))
set @datos =(select ape +','+nom from users where dni=@dni )
else
set @datos ='datos incorrectos'
end
go
insert users values('10203040','myPass','Rios flores','Jose'),
('44556677','asd123','Paz gomes','Cinthia')
go
declare @datos varchar(62)
exec loguear '10203040','myPass',@datos output
select @datos
go
declare @datos varchar(62)
exec loguear '44556677','asd123',@datos output
select @datos
go
]
Imports System.Data
Imports System.Data.SqlClient
Module Module1
Public Con As New SqlConnection("Data Source=.;DataBase=tienda;Integrated Security=true")
Public Sub abrir()
If Con.State = 0 Then Con.Open()
End Sub
Sub cerrar()
If Con.State = 1 Then Con.Close()
End Sub
Public clave As String
End Module
]
Imports System.Data
Imports System.Data.SqlClient
Public Class acceso
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ingresar()
txtdni.Text = ""
txtclave.Text = ""
End Sub
Sub ingresar()
Dim cmd As SqlCommand
Dim msj As String
Try
Call abrir()
cmd = New SqlCommand("loguear", Con)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
.AddWithValue("@dni", txtdni.Text)
.AddWithValue("@clave", txtclave.Text)
.Add("@datos", SqlDbType.VarChar, 62).Direction = 2
End With
cmd.ExecuteNonQuery()
msj = cmd.Parameters("@datos").Value
MessageBox.Show(msj)
clave = cmd.Parameters("@datos").Value
Me.Hide()
My.Forms.accesoactivo.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Call cerrar()
End Sub
End Class
]
Imports System.Data
Imports System.Data.SqlClient
Public Class accesoactivo
Private Sub accesoactivo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ttxtdatos.Text = clave
End Sub
End Class
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Public Class Form2
Const WinkTimerInterval As Integer = 150 ' En milisegundos
Protected eyeImages(6) As Image
Protected currentImage As Integer = 0
Protected animationStep As Integer = 1
Const BallTimerInterval As Integer = 25 ' En milisegundos
Private ballSize As Integer = 16 ' Como una fracción del área de cliente
Private moveSize As Integer = 4 ' Como una fracción del tamaño de la pelota
Private bitmap As Bitmap
Private ballPositionX As Integer
Private ballPositionY As Integer
Private ballRadiusX As Integer
Private ballRadiusY As Integer
Private ballMoveX As Integer
Private ballMoveY As Integer
Private ballBitmapWidth As Integer
Private ballBitmapHeight As Integer
Private bitmapWidthMargin As Integer
Private bitmapHeightMargin As Integer
Const TextTimerInterval As Integer = 15 ' En milisegundos
Protected currentGradientShift As Integer = 10
Protected gradiantStep As Integer = 5
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
eyeImages(0) = My.Resources.dorita
eyeImages(1) = My.Resources.bwall58
eyeImages(2) = My.Resources.dorita
eyeImages(3) = My.Resources.aioros
eyeImages(4) = My.Resources.assasain
eyeImages(5) = My.Resources.bwall58
End Sub
Private Sub exitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub optWink_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optWink.CheckedChanged
If optWink.Checked Then
tmrAnimation.Interval = WinkTimerInterval
ElseIf optBall.Checked Then
tmrAnimation.Interval = BallTimerInterval
ElseIf optText.Checked Then
tmrAnimation.Interval = TextTimerInterval
End If
OnResize(EventArgs.Empty)
End Sub
Private Sub optBall_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optBall.CheckedChanged
If optWink.Checked Then
tmrAnimation.Interval = WinkTimerInterval
ElseIf optBall.Checked Then
tmrAnimation.Interval = BallTimerInterval
ElseIf optText.Checked Then
tmrAnimation.Interval = TextTimerInterval
End If
OnResize(EventArgs.Empty)
End Sub
Protected Overrides Sub OnResize(ByVal ea As EventArgs)
If optWink.Checked Then
' Obtenga el objeto Graphics expuesto por el formulario y borre todos los dibujos.
Dim grfx As Graphics = CreateGraphics()
' También puede llamar a grfx.Clear(BackColor) o Me.Invalidate() para borrar
' la pantalla.
Me.Refresh()
grfx.Dispose()
ElseIf optBall.Checked Then
' Obtenga el objeto Graphics expuesto por el formulario y borre todos los dibujos.
Dim grfx As Graphics = CreateGraphics()
grfx.Clear(BackColor)
' Defina el radio de la pelota en una fracción del ancho o el alto
' del área de cliente, el que sea menor.
Dim dblRadius As Double = Math.Min(ClientSize.Width / grfx.DpiX, _
ClientSize.Height / grfx.DpiY) / ballSize
' Defina el ancho y el alto de la pelota, ya que normalmente el DPI es
' idéntico en los ejes X e Y.
ballRadiusX = CInt(dblRadius * grfx.DpiX)
ballRadiusY = CInt(dblRadius * grfx.DpiY)
grfx.Dispose()
' Defina la distancia que recorre la pelota en 1 píxel o en una fracción del
' tamaño de la pelota, lo que sea mayor. De esta forma, la distancia que
' recorre la pelota cada vez que se dibuja será proporcional a su tamaño que,
' a su vez, será proporcional al tamaño del área de cliente. Por tanto, cuando
' el área de cliente se reduce, disminuye la velocidad de la pelota, y cuando
' aumenta, se incrementa la velocidad de la pelota.
ballMoveX = CInt(Math.Max(1, ballRadiusX / moveSize))
ballMoveY = CInt(Math.Max(1, ballRadiusY / moveSize))
'Observe que el valor del movimiento de la pelota sirve también como
' margen en torno a la pelota, que determina el tamaño del mapa de bits
' real en el que se dibuja la pelota. Por tanto, la distancia recorrida por la pelota
' es exactamente igual al tamaño del mapa de bits, lo que permite borrar
' la imagen anterior de la pelota antes de que se dibuje la siguiente imagen, y
' todo ello sin que se produzca un parpadeo excesivo.
bitmapWidthMargin = ballMoveX
bitmapHeightMargin = ballMoveY
' Determine el tamaño real del mapa de bits en el que se dibuja la pelota
' agregando los márgenes a las dimensiones de la pelota.
ballBitmapWidth = 2 * (ballRadiusX + bitmapWidthMargin)
ballBitmapHeight = 2 * (ballRadiusY + bitmapHeightMargin)
' Cree un nuevo mapa de bits pasando el ancho y el alto
bitmap = New Bitmap(ballBitmapWidth, ballBitmapHeight)
' Obtenga el objeto Graphics expuesto por el mapa de bits, limpie la pelota
' existente y dibuje la nueva pelota.
grfx = Graphics.FromImage(bitmap)
With grfx
.Clear(BackColor)
.FillEllipse(Brushes.Red, New Rectangle(ballMoveX, _
ballMoveY, 2 * ballRadiusX, 2 * ballRadiusY))
.Dispose()
End With
' Restablezca la posición de la pelota en el centro del área de cliente.
ballPositionX = CInt(ClientSize.Width / 2)
ballPositionY = CInt(ClientSize.Height / 2)
ElseIf optText.Checked Then
' Obtenga el objeto Graphics expuesto por el formulario y borre todos los dibujos.
Dim grfx As Graphics = CreateGraphics()
grfx.Clear(BackColor)
End If
End Sub
Private Sub tmrAnimation_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnimation.Tick
If optWink.Checked Then
' Obtenga el objeto Graphics expuesto por el formulario.
Dim grfx As Graphics = CreateGraphics()
' Llame a DrawImage, mediante Overload #8, que obtiene la imagen actual para su
' presentación, las coordenadas X e Y (que, en este caso, centra la
' imagen en el área de cliente) y el ancho y alto de la imagen.
grfx.DrawImage(eyeImages(currentImage), _
CInt((ClientSize.Width - eyeImages(currentImage).Width) / 2), _
CInt((ClientSize.Height - eyeImages(currentImage).Height) / 2), _
eyeImages(currentImage).Width, _
eyeImages(currentImage).Height)
' Es aconsejable que siempre se llame a Dispose para los objetos que exponen este
' método, en lugar de esperar a que el recolector de elementos no utilizados se ejecute automáticamente.
' De esta forma, obtendrá siempre un mayor rendimiento de la aplicación.
grfx.Dispose()
' Recorra en bucle las imágenes.
currentImage += animationStep
If currentImage = 5 Then
' Ésta es la última imagen de las cuatro, por lo que debe invertir el orden de
' animación .
animationStep = -1
ElseIf currentImage = 0 Then
' Ésta es la primera imagen , por lo que debe invertir el orden de
' animación
animationStep = 1
End If
ElseIf optBall.Checked Then
' Obtenga el objeto Graphics expuesto por el formulario.
Dim grfx As Graphics = CreateGraphics()
' Dibuje el mapa de bits que contiene la pelota en el formulario.
grfx.DrawImage(bitmap, _
CInt(ballPositionX - ballBitmapWidth / 2), _
CInt(ballPositionY - ballBitmapHeight / 2), _
ballBitmapWidth, ballBitmapHeight)
grfx.Dispose()
' Aumente la posición de la pelota en la distancia que se ha
' movido en las coordenadas X e Y después de haber sido redibujada.
ballPositionX += ballMoveX
ballPositionY += ballMoveY
' Invierta la dirección de la pelota cuando toque un extremo.
If ballPositionX + ballRadiusX >= ClientSize.Width _
Or ballPositionX - ballRadiusX <= 0 Then
ballMoveX = -ballMoveX
Beep()
End If
' Defina el extremo Y en 80 en lugar de en 0 para que la pelota no rebote
' en los controles del formulario.
If ballPositionY + ballRadiusY >= ClientSize.Height _
Or ballPositionY - ballRadiusY <= 80 Then
ballMoveY = -ballMoveY
Beep()
End If
ElseIf optText.Checked Then
' Obtenga el objeto Graphics expuesto por el formulario.
Dim grfx As Graphics = CreateGraphics()
' Defina el tipo de fuente, el texto y determine su tamaño.
Dim font As New Font("Microsoft Sans Serif", 96, _
FontStyle.Bold, GraphicsUnit.Point)
Dim strText As String = "Javier_Vidarte_Delgado "
Dim sizfText As New SizeF(grfx.MeasureString(strText, font))
' Defina el punto en el que se va a dibujar el texto: centrado
' en el área de cliente.
Dim ptfTextStart As New PointF( _
CSng(ClientSize.Width - sizfText.Width) / 2, _
CSng(ClientSize.Height - sizfText.Height) / 2)
' Defina el punto inicial y final de inclinación; este último se ajustará
' mediante un valor cambiante para producir el efecto de animación.
Dim ptfGradientStart As New PointF(0, 0)
Dim ptfGradientEnd As New PointF(currentGradientShift, 200)
' Cree una instancia del pincel utilizado para dibujar el texto.
Dim grBrush As New LinearGradientBrush(ptfGradientStart, _
ptfGradientEnd, Color.Blue, BackColor)
' Dibuje el texto centrado en el área de cliente.
grfx.DrawString(strText, font, grBrush, ptfTextStart)
grfx.Dispose()
' Mueva la inclinación e inviértala cuando obtenga un determinado valor.
currentGradientShift += gradiantStep
If currentGradientShift = 500 Then
gradiantStep = -5
ElseIf currentGradientShift = -50 Then
gradiantStep = 5
End If
End If
End Sub
End Class
Dim aleatorio As Integer()
Dim r As New Random
ReDim aleatorio(2)
'asignando valores
For i As Integer = 0 To aleatorio.Length - 1
aleatorio(i) = r.Next(1, 5)
TextBox1.Text = aleatorio(i)
Next
For j As Integer = 0 To aleatorio.Length - 1
aleatorio(j) = r.Next(1, 5)
TextBox2.Text = aleatorio(j)
TextBox1.Text = aleatorio(j)
Next
For k As Integer = 0 To aleatorio.Length - 1
aleatorio(k) = r.Next(1, 5)
TextBox3.Text = aleatorio(k)
If TextBox2.Text = aleatorio(k) Then
MessageBox.Show("ganastes")
End If
Next
go
use master
go
set language spanish
go
if(DB_ID('ejemplo')is not null)
drop database ejemplo
go
create database ejemplo
go
use ejemplo
go
create table individuo
(dni char(8) primary key,
apellidos varchar(30) not null,
nombre varchar(30) not null,
sexo char(1) not null check (sexo in('M','F')),
fecnac date not null,
edad tinyint not null,
salario money)
go
create proc registrar(@dni char(8),
@ape varchar(30),
@n varchar(30),
@s char(1),
@fn date,
@e tinyint,
@sueldo money,
@msj varchar(60)output)
as begin
if(not exists(select * from individuo where dni =@dni ))
begin
insert into individuo values(@dni,@ape,@n,@s,@fn,@e,@sueldo)
set @msj ='REGISTRADO'
end
else
--NO EXISTE UNA PERSONA CON EL MISMO DNI
set @msj ='DNI YA EXISTE'
end
GO
create proc modificar(@dni char(8),
@ape varchar(30),
@n varchar(30),
@s char(1),
@fn date,
@e tinyint,
@sueldo money,
@msj varchar(60)output)
as begin
if(exists(select * from individuo where dni =@dni ))
begin
update individuo set apellidos =@ape ,nombre =@n ,sexo =@s ,fecnac =@fn ,edad =@e ,salario =@sueldo where dni =@dni
set @msj ='Datos modificados'
end
else
set @msj ='DNI no existe'
end
go
create proc eliminar(@dni char(8),@msj varchar(60)output)
as begin
if(exists(select * from individuo where dni =@dni ))
begin
delete from individuo where dni =@dni
set @msj ='Datos eliminados'
end
else
set @msj ='DNI no existe'
end
Imports System.Data
Imports System.Data.SqlClient
Module Module1
Public con As New SqlConnection("Data Source=.;DataBase=ejemplo;Integrated Security=true")
Public Sub abrir()
If con.State = 0 Then con.Open()
End Sub
Public Sub cerrar()
If con.State = 1 Then con.Close()
End Sub
End Module
Imports System.Data
Imports System.Data.SqlClient
Public Class Class1
Private m_dni, m_ape, m_n, m_s As String
Private m_fn As Date
Private m_edad As Integer
Private m_sueldo As Decimal
Public Property dni() As String
Get
Return m_dni
End Get
Set(ByVal value As String)
m_dni = value
End Set
End Property
Public Property ape() As String
Get
Return m_ape
End Get
Set(ByVal value As String)
m_ape = value
End Set
End Property
Public Property n() As String
Get
Return m_n
End Get
Set(ByVal value As String)
m_n = value
End Set
End Property
Public Property s() As String
Get
Return m_s
End Get
Set(ByVal value As String)
m_s = value
End Set
End Property
Public Property fn() As Date
Get
Return m_fn
End Get
Set(ByVal value As Date)
m_fn = value
End Set
End Property
Public Property edad() As Integer
Get
Return m_edad
End Get
Set(ByVal value As Integer)
m_edad = value
End Set
End Property
Public Property sueldo() As Decimal
Get
Return m_sueldo
End Get
Set(ByVal value As Decimal)
m_sueldo = value
End Set
End Property
Public Function listado()
Dim dt As New DataTable
Dim da As SqlDataAdapter
Try
abrir()
da = New SqlDataAdapter("select *from individuo", con)
da.Fill(dt)
Catch ex As Exception : Throw ex
End Try
cerrar()
Return dt
End Function
Public Function registrar() As String
Dim msj As String
Dim cmd As SqlCommand
Try
'@dni,@idt ,@ape,@nom,@sex,@fn,@fi,@fono,@est
abrir()
cmd = New SqlCommand("registrar", con)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
cmd.Parameters.AddWithValue("@dni", dni)
cmd.Parameters.AddWithValue("@ape", ape)
cmd.Parameters.AddWithValue("@n", n)
cmd.Parameters.AddWithValue("@s", s)
cmd.Parameters.AddWithValue("@fn", fn)
cmd.Parameters.AddWithValue("@e", edad)
cmd.Parameters.AddWithValue("@sueldo", sueldo)
cmd.Parameters.Add("@msj", SqlDbType.VarChar, 30).Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()
msj = cmd.Parameters("@msj").Value
End With
Catch ex As Exception : Throw ex
End Try
cerrar()
Return msj
End Function
Public Function modificar() As String
Dim msj As String
Dim cmd As SqlCommand
Try
'@dni,@idt ,@ape,@nom,@sex,@fn,@fi,@fono,@est
abrir()
cmd = New SqlCommand("modificar", con)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
cmd.Parameters.AddWithValue("@dni", dni)
cmd.Parameters.AddWithValue("@ape", ape)
cmd.Parameters.AddWithValue("@n", n)
cmd.Parameters.AddWithValue("@s", s)
cmd.Parameters.AddWithValue("@fn", fn)
cmd.Parameters.AddWithValue("@e", edad)
cmd.Parameters.AddWithValue("@sueldo", sueldo)
cmd.Parameters.Add("@msj", SqlDbType.VarChar, 30).Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()
msj = cmd.Parameters("@msj").Value
End With
Catch ex As Exception : Throw ex
End Try
cerrar()
Return msj
End Function
Public Function eliminar() As String
Dim msj As String
Dim cmd As SqlCommand
Try
'@dni,@idt ,@ape,@nom,@sex,@fn,@fi,@fono,@est
abrir()
cmd = New SqlCommand("eliminar", con)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
cmd.Parameters.AddWithValue("@dni", dni)
cmd.Parameters.Add("@msj", SqlDbType.VarChar, 30).Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()
msj = cmd.Parameters("@msj").Value
End With
Catch ex As Exception : Throw ex
End Try
cerrar()
Return msj
End Function
End Class
Imports biblioteca
Public Class Form1
Public p As New biblioteca.Class1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
listado()
RadioButton1.Checked = True
End Sub
Sub listado()
Try
DataGridView1.DataSource = p.listado()
Catch ex As Exception : MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
p.dni = TextBox1.Text
p.ape = TextBox2.Text
p.n = TextBox3.Text
If RadioButton1.Checked = True Then
p.s = "M"
Else
p.s = "F"
End If
p.fn = DateTimePicker1.Value
p.edad = TextBox4.Text
p.sueldo = TextBox5.Text
MessageBox.Show(p.registrar())
Catch ex As Exception : MessageBox.Show(ex.Message)
End Try
listado()
limpiar()
End Sub
Sub limpiar()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox1.ReadOnly = False
TextBox5.Clear()
DateTimePicker1.Value = Now
RadioButton1.Checked = True
TextBox1.Focus()
End Sub
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
Dim ed As Integer
ed = Now.Year - DateTimePicker1.Value.Year
TextBox4.Text = ed
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
p.dni = TextBox1.Text
p.ape = TextBox2.Text
p.n = TextBox3.Text
If RadioButton1.Checked = True Then
p.s = "M"
Else
p.s = "F"
End If
p.fn = DateTimePicker1.Value
p.edad = TextBox4.Text
p.sueldo = TextBox5.Text
MessageBox.Show(p.modificar())
Catch ex As Exception : MessageBox.Show(ex.Message)
End Try
listado()
limpiar()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
p.dni = TextBox1.Text
MessageBox.Show(p.eliminar())
Catch ex As Exception : MessageBox.Show(ex.Message)
End Try
listado()
limpiar()
End Sub
Private Sub DataGridView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
Try
Dim fila As Integer = DataGridView1.CurrentRow.Index
With DataGridView1.Rows(fila)
TextBox1.Text = .Cells(0).Value.ToString
TextBox2.Text = .Cells(1).Value.ToString
TextBox3.Text = .Cells(2).Value.ToString
If .Cells(3).Value.ToString = "M" Then
RadioButton1.Checked = True
Else
RadioButton2.Checked = True
End If
DateTimePicker1.Value = .Cells(4).Value.ToString
TextBox4.Text = .Cells(5).Value.ToString
TextBox5.Text = .Cells(6).Value.ToString
End With
TextBox1.ReadOnly = True
Catch ex As Exception : MessageBox.Show("fila sin datos")
End Try
End Sub
End Class