You are on page 1of 3

BASE DE DATOS SQLSERVER

create database Transporte


use Transporte
go

create table Pasajeros(


DNI char (8) primary key not null,
Apenom varchar (35) not null,
Fenac date not null,
Varon char(1) not null,
Destino varchar (15) not null,
Pago real not null,
Peso numeric not null
)
go

select * from Pasajeros


VISUAL STUDIO - FORMULARIO

CODIGO VISUAL STUDIO

Imports System
Imports System.Data.SqlClient
Public Class Form1
Dim conexion As New SqlConnection
Dim comando As New SqlCommand
Dim v As Char
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Try
conexion.ConnectionString = ("Data Source=SANTI-PC\SQLEXPRESS;Initial
Catalog=Transporte;Integrated Security=True")
conexion.Open()
comando.Connection = conexion
MsgBox("BIENVIENIDO", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox("ERROR EN LA CONEXION CON LA BASE DE DATOS", MsgBoxStyle.Critical)

End Try
End Sub

Private Sub btnagregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnagregar.Click
comando.CommandText = "insert into Pasajeros(DNI, Apenom, Fenac, Varon, Destino, Pago,
Peso) values ('" & txtDNI.Text & "','" & txtNombre.Text & "','" & CDate(dtpFenac.Text) & "','" & v
& "','" & cboDestino.Text & "','" & lblPago.Text & "','" & nudPeso.Value & "')"
comando.ExecuteNonQuery()
txtDNI.Clear()
txtNombre.Clear()

End Sub
Private Sub cboDestino_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cboDestino.SelectedIndexChanged
Dim d As String
d = cboDestino.Text
Select Case d
Case "Juliaca"
lblPago.Text = 15
Case "Puno"
lblPago.Text = 20
Case "Tacna"
lblPago.Text = 20
Case "Cuzco"
lblPago.Text = 75
Case "Lima"
lblPago.Text = 60
End Select
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
v = "S"
Else
v = "N"
End If

End Sub
End Class

You might also like