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

1.- Crear la Base de datos en ACCESS con el nombre de Prueba1.accdb ubicado en el disco D.

, cuya Tabla debe


llamarse Datos1, siguiendo la secuencia del ppt, pero cuidando los nombres que te indico.

2.- En Visual 2008, crear el siguiente Formulario, (sus características están en el ppt):

3.- Añadir un Módulo, cuyo texto es el siguiente:

Module Module1
Public Conexion As ADODB.Connection
Public Sub conectar()
Conexion = New ADODB.Connection
Conexion.ConnectionString = "provider=microsoft.ACE.oledb.12.0;Data _
Source=D:\prueba11.accdb"
Conexion.Open()
End Sub
End Module

4.- Los controles Button estàn en el orden button1, button2, button3, button4 y
button5.

5.- Programar en la secuencia del ppt, y aquí está la codificación:

Public Class Form1


Public accion As String
Public sql As String

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


Handles MyBase.Load
conectar()
cmb_sem.Items.Add("Ing. en Sistemas")
cmb_sem.Items.Add("Lic. en Informática")
cmb_sem.Items.Add("Ing. Electrónica")
cmb_sem.Items.Add("Lic. en Contabilidad")
cmb_sem.Items.Add("Ing. Industrial")
End Sub

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


System.EventArgs) Handles Button1.Click
txt_nocontrol.Text = ""
txt_nocontrol.Enabled = True
txt_nombre.Text = ""
txt_nombre.Enabled = True
txt_ap.Text = ""
txt_ap.Enabled = True
txt_am.Text = ""
txt_am.Enabled = True
cmb_sem.Text = ""
cmb_sem.Enabled = True
accion = "nuevo"
End Sub

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


System.EventArgs) Handles Button2.Click
txt_nombre.Enabled = True
txt_ap.Enabled = True
txt_am.Enabled = True
cmb_sem.Enabled = True
accion = "editar"
End Sub

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


System.EventArgs) Handles Button3.Click
Dim numero As String
Dim rs As ADODB.Recordset

numero = InputBox("Digite el numero de control")


sql = "Select * from datos1 where noControl='" & numero & "'"
rs = Conexion.Execute(sql)

If rs.BOF <> True Then


txt_nocontrol.Text = rs.Fields(0).Value
txt_nombre.Text = rs.Fields(1).Value
txt_ap.Text = rs.Fields(2).Value
txt_am.Text = rs.Fields(3).Value
cmb_sem.Text = rs.Fields(4).Value
Else
MsgBox("El registro no existe")
End If
End Sub

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


System.EventArgs) Handles Button4.Click
If accion = "nuevo" Then
sql = "insert into datos1 (noControl,nombre,aPaterno,aMaterno,carrera)" _
& "values ('" & txt_nocontrol.Text & "','" & txt_nombre.Text & "','" _
& txt_ap.Text & "','" & txt_am.Text & "','" & cmb_sem.Text & "')"
Conexion.Execute(sql)
MsgBox("El registro se guardo correctamente")
End If
If accion = "editar" Then
sql = "update datos1 set nombre='" & txt_nombre.Text & "', " _
& "aPaterno='" & txt_ap.Text & "', " _
& "aMaterno='" & txt_am.Text & "', " _
& "carrera='" & cmb_sem.Text & "' " _
& "where nocontrol='" & txt_nocontrol.Text & "'"
Debug.Print(sql)

Conexion.Execute(sql)
MsgBox("La edicion del registro se realizá con éxito")
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Dim x As Integer
x = MsgBox("En realidad quiere elimonar el registro?", MsgBoxStyle.YesNo)
If x = vbYes Then
sql = "delete from datos1 where nocontrol='" & txt_nocontrol.Text & "'"
Conexion.Execute(sql)
MsgBox("Registro eliminado")
txt_nocontrol.Text = ""
txt_nombre.Text = ""
txt_ap.Text = ""
txt_am.Text = ""
cmb_sem.Text = ""
End If
End Sub
End Class

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