You are on page 1of 5

www.youtube.

com/georgemaykol
APLICACIN EN VISUAL BASIC.NET 2010 CON BASE DE DATOS EN ACCESS 2010

P.T. Maykol

Otiniano Avila

1.

Crear el directorio:

2.

Abrir ACCESS y crear una base de datos con el nombre colegio, en la carpeta data del directorio que hemos creado

3.

Creamos la tabla alumno NOMBRE DEL CAMPO al_codi al_apel al_nomb al_sexo al_fena al_dire al_tele al_coel TIPO DE DATOS Texto Texto Texto Texto Fecha/Hora Texto Texto Texto DESCRIPCIN Cdigo de alumno Apellidos del alumno Nombres del alumno Sexo Fecha de nacimiento Direccin Telfono Correo electrnico 150 6 45 5 50 50 1 Fecha corta TAMAO DEL CAMPO FORMATO

El campo al_codi es la Clave Principal

4.

Ahora cierra Access porque vamos a Cifrar con contrasea la base de datos que hemos creado, para restringir el acceso a la misma; para ello seguimos los pasos: 4.1. Abrir Access 4.2. Seleccionamos Archivo/Abrir 4.3. Ubicamos la base de datos, la seleccionamos y en el botn Abrir elegimos Abrir en modo exclusivo 4.4. Ahora vamos a Archivo/Cifrar con contrasea 4.5. Escribimos la contrasea y luego la confirmamos (mi contrasea es ptgmoa); finalmente hacemos clic en el botn ACEPTAR 4.6. Si sale algn otro mensaje solo das clic en ACEPTAR Ya est la base de datos est protegida por contrasea Cierra Access

www.youtube.com/georgemaykol
5. formulario:

P.T. Maykol

Otiniano Avila

Abre Visual Basic .Net, creas un nuevo proyecto con el nombre colegio y diseamos el siguiente

6.

Modificamos las propiedades de los objetos OBJETO Form1 Label1 Label2 Label3 Label4 Label5 Label6 Label7 Label8 TextBox1 TextBox2 TextBox3 TextBox4 DateTimePicker1 TextBox5 TextBox6 TextBox7 Button1 Button2 Button3 Button4 Button5 Button6 Button7 PROPIEDAD Name Text ControlBox Text Text Text Text Text Text Text Text Name MaxLength Name MaxLength Name MaxLength Name MaxLength Name Format Name MaxLength Name MaxLength Name MaxLength Name Text Name Text Name Text Name Text Name Text Name Text Name Text VALOR frmAlumno Datos del Alumno False Cdigo Apellidos Nombres Sexo Fecha de nacimiento Direccin Telfono Correo txtCod 7 txtApe 50 txtNom 50 txtSex 1 dtpFec Short txtDir 150 txtTel 6 txtCor 45 btnNue NUEVO btnEdi EDITAR btnBor BORRAR btnSal SALIR btnPri << btnAnt < btnSig >

www.youtube.com/georgemaykol
Button8 Name Text btnUlt >>

P.T. Maykol

Otiniano Avila

7. 8.

Guardas el proyecto en la carpeta colegio. Escribimos el cdigo

Imports System.Data.OleDb

Public Class frmAlumno


Dim strConexion As String = "Provider=Microsoft.ACE.OLEDB.12.0; DATA SOURCE = D:\colegio\data\colegio.accdb; Jet OLEDB:Database Password=ptgmoa;" Dim strComando As String = "Select * from alumno" Dim DA As OleDbDataAdapter Dim DS As New DataSet Dim CB As OleDbCommandBuilder Dim Posicion As Integer Private Sub BloquearBotones() btnBor.Enabled = False btnSal.Enabled = False btnPri.Enabled = False btnAnt.Enabled = False btnSig.Enabled = False btnUlt.Enabled = False End Sub Private Sub DesbloquearBotones() btnBor.Enabled = True btnSal.Enabled = True btnPri.Enabled = True btnAnt.Enabled = True btnSig.Enabled = True btnUlt.Enabled = True End Sub Private Sub frmAlumno_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try DA = New OleDbDataAdapter(strComando, strConexion) DA.Fill(DS, "alumno") CB = New OleDbCommandBuilder(DA) txtCod.DataBindings.Add(New Binding("Text", DS, "alumno.al_codi")) txtApe.DataBindings.Add(New Binding("Text", DS, "alumno.al_apel")) txtNom.DataBindings.Add(New Binding("Text", DS, "alumno.al_nomb")) txtSex.DataBindings.Add(New Binding("Text", DS, "alumno.al_sexo")) dtpFec.DataBindings.Add(New Binding("Value", DS, "alumno.al_fena")) txtDir.DataBindings.Add(New Binding("Text", DS, "alumno.al_dire")) txtTel.DataBindings.Add(New Binding("Text", DS, "alumno.al_tele")) txtCor.DataBindings.Add(New Binding("Text", DS, "alumno.al_coel")) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub btnNue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNue.Click If btnNue.Text = "NUEVO" Then Me.BindingContext(DS, "alumno").AddNew() txtCod.Focus() btnNue.Text = "GUARDAR" btnEdi.Text = "CANCELAR" BloquearBotones() Else Try

www.youtube.com/georgemaykol
BindingContext(DS, "alumno").EndCurrentEdit() DA.Update(DS, "alumno") DS.Tables("alumno").AcceptChanges() btnNue.Text = "NUEVO" btnEdi.Text = "EDITAR" DesbloquearBotones() Catch ex As Exception MsgBox(ex.Message) End Try End If End Sub

P.T. Maykol

Otiniano Avila

Private Sub btnEdi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdi.Click If btnEdi.Text = "EDITAR" Then If txtCod.Text = "" Then MsgBox("No existen registros para editar", MsgBoxStyle.Critical, "Error") Else btnNue.Text = "GUARDAR" btnEdi.Text = "CANCELAR" BloquearBotones() End If Else BindingContext(DS, "alumno").CancelCurrentEdit() btnNue.Text = "NUEVO" btnEdi.Text = "EDITAR" DesbloquearBotones() End If End Sub Private Sub btnBor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBor.Click If txtCod.Text = "" Then MsgBox("No hay registros para eliminar", MsgBoxStyle.Critical, "Error") Else If MsgBox("Est seguro que desea eliminar el registro?", MsgBoxStyle.YesNo, "Eliminar") = MsgBoxResult.Yes Then Posicion = BindingContext(DS, "alumno").Position DS.Tables("alumno").Rows(Posicion).Delete() DA.Update(DS, "alumno") DS.Tables("alumno").AcceptChanges() End If End If End Sub Private Sub btnSal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSal.Click End End Sub Private Sub btnPri_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPri.Click Me.BindingContext(DS, "alumno").Position = 0 End Sub Private Sub btnAnt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnt.Click Me.BindingContext(DS, "alumno").Position -= 1 End Sub Private Sub btnSig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSig.Click Me.BindingContext(DS, "alumno").Position += 1 End Sub

www.youtube.com/georgemaykol

P.T. Maykol

Otiniano Avila

Private Sub btnUlt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUlt.Click Me.BindingContext(DS, "alumno").Position = BindingContext(DS, "alumno").Count End Sub

End Class

9.

Guarden los cambios y Ejecuten el Programa

Dios les bendiga

You might also like