![Page 1: Códigos fuentes aplicativo Agenda con VB³digos fuentes aplicativo Agenda con VB.NET Códigos fuente del aplicativo desarrollado en Visual Basic .Net, para el formulario Agenda.vb](https://reader031.vdocuments.pub/reader031/viewer/2022012923/5b1a4cff7f8b9a28258d5cd8/html5/thumbnails/1.jpg)
Códigos fuentes
aplicativo Agenda con
VB.NET
Códigos fuente del aplicativo desarrollado en Visual Basic .Net, para el formulario
Agenda.vb y el módulo funciones.vb
2011
Andres
[Escriba el nombre de la compañía]
01/01/2011
Ver código fuente de Agenda.vb
Ver código fuente de funciones.vb
![Page 2: Códigos fuentes aplicativo Agenda con VB³digos fuentes aplicativo Agenda con VB.NET Códigos fuente del aplicativo desarrollado en Visual Basic .Net, para el formulario Agenda.vb](https://reader031.vdocuments.pub/reader031/viewer/2022012923/5b1a4cff7f8b9a28258d5cd8/html5/thumbnails/2.jpg)
AGENDA.VB
Imports MySql Imports MySql.Data.MySqlClient
Public Class Agenda
Public pbus As String Public idactual As Integer
Private Sub consultaxcodigo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
consultaxcodigo.Click
param.Text = "Código estudiante"
pbus = "COD_EST" parbusqueda.Clear()
pconsulta.Visible = True
borratb()
Me.Height = 108
bagregar.Enabled = False
modificar.Enabled = True
eliminar.Enabled = True End Sub
Private Sub consultaxapellidos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles consultaxapellidos.Click
param.Text = "Apellidos"
pbus = "APELLIDOS" parbusqueda.Clear()
pconsulta.Visible = True
borratb()
Me.Height = 108 bagregar.Enabled = False
modificar.Enabled = True
eliminar.Enabled = True
End Sub
Private Function borratb()
tbcodigo.Clear()
tbapellidos.Clear()
tbnombres.Clear()
tbdocumento.Clear()
tbtelefono.Clear()
fecha.Value = Date.Today
Return 0 End Function
Private Sub bconsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
bconsultar.Click
Dim datos As MySqlDataReader
If parbusqueda.TextLength <> 0 Then Dim parbuscar As String = "'" & parbusqueda.Text & "'"
If conexion(True) Then
datos = consultar("SELECT * FROM datos WHERE " & pbus & "=" & parbuscar & ";")
If datos.HasRows <> 0 Then
datos.Read()
idactual = datos("ID_EST")
tbcodigo.Text = datos("COD_EST") tbapellidos.Text = datos("APELLIDOS")
tbnombres.Text = datos("NOMBRES")
tbdocumento.Text = datos("NO_DI")
fecha.Value = datos("FECHA_NACE")
![Page 3: Códigos fuentes aplicativo Agenda con VB³digos fuentes aplicativo Agenda con VB.NET Códigos fuente del aplicativo desarrollado en Visual Basic .Net, para el formulario Agenda.vb](https://reader031.vdocuments.pub/reader031/viewer/2022012923/5b1a4cff7f8b9a28258d5cd8/html5/thumbnails/3.jpg)
tbtelefono.Text = datos("TELEFONO") datos.Close()
Me.Height = 334
Else
MsgBox("No se han encontrado registros para su búsqueda", MsgBoxStyle.Information,
"Registro no encontrado")
End If
con.Close()
End If
End If
End Sub
Private Sub Agenda_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Height = 108 fecha.CustomFormat = "d 'de' MMMM 'de' yyy" ' definimos el formato con que nos va mostrar la fecha
en el datatimepicker
End Sub
Private Sub modificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
modificar.Click
If conexion(True) Then
Try
actualizar("UPDATE datos SET COD_EST='" & tbcodigo.Text & "', APELLIDOS='" &
tbapellidos.Text & _ "', NOMBRES='" & tbnombres.Text & "', NO_DI='" & tbdocumento.Text &
"', FECHA_NACE='" & _
fecha.Value.ToString("yyyy-MM-dd") & "', TELEFONO='" & tbtelefono.Text & "' WHERE ID_EST=" & idactual & ";")
MsgBox("El registro se ha modificado exitosamente", MsgBoxStyle.Information, "Modificación
exitosa")
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End If
con.Close()
End Sub
Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
eliminar.Click
If conexion(True) Then
Try
consultar("DELETE from datos WHERE ID_EST=" & idactual & ";")
MsgBox("El registro se ha borrado exitosamente", MsgBoxStyle.Information, "Borrado
exitoso") Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End If
con.Close()
End Sub
Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
agregar.Click
Me.Height = 334
pconsulta.Visible = False
borratb()
bagregar.Enabled = True
modificar.Enabled = False
eliminar.Enabled = False
End Sub
![Page 4: Códigos fuentes aplicativo Agenda con VB³digos fuentes aplicativo Agenda con VB.NET Códigos fuente del aplicativo desarrollado en Visual Basic .Net, para el formulario Agenda.vb](https://reader031.vdocuments.pub/reader031/viewer/2022012923/5b1a4cff7f8b9a28258d5cd8/html5/thumbnails/4.jpg)
Private Sub Cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cerrar.Click
Me.Close()
End Sub
Private Sub bagregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
bagregar.Click
If conexion(True) Then
Try
actualizar("INSERT INTO datos (COD_EST,APELLIDOS, NOMBRES,NO_DI,FECHA_NACE,TELEFONO) VALUES
('" & _
tbcodigo.Text & "','" & tbapellidos.Text & "','" & tbnombres.Text & "','" &
tbdocumento.Text & _
"','" & fecha.Value.ToString("yyyy-MM-dd") & "','" & tbtelefono.Text & "');") MsgBox("El registro se ha creado exitosamente", MsgBoxStyle.Information, "Creación
exitosa")
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End If
con.Close()
End Sub
End Class
![Page 5: Códigos fuentes aplicativo Agenda con VB³digos fuentes aplicativo Agenda con VB.NET Códigos fuente del aplicativo desarrollado en Visual Basic .Net, para el formulario Agenda.vb](https://reader031.vdocuments.pub/reader031/viewer/2022012923/5b1a4cff7f8b9a28258d5cd8/html5/thumbnails/5.jpg)
FUNCIONES.VB
Imports MySql Imports MySql.Data.MySqlClient
Imports System.Data
Module funciones
Public con As MySqlConnection
Public Function conexion(ByVal msg As Boolean)
con = New MySqlConnection()
con.ConnectionString = "server=localhost; user id=usuariosgd; password=sgd11; database=sgd11;" Try
con.Open()
conexion = True Catch mierror As MySqlException
conexion = False
If msg Then
MsgBox("No ha sido posible conectarse al sistema" & Chr(13) & _ mierror.Message.ToString & Chr(13) & _
"Intentelo más tarde o verifique la conexión al Servidor", _
MsgBoxStyle.Critical, "Error al conectarse al Sistema")
End If
End Try
End Function
Public Function consultar(ByVal busqueda As String) As MySqlDataReader
Dim myadapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.Connection = con
command.CommandText = busqueda
myadapter.SelectCommand = command
consultar = command.ExecuteReader
End Function
Public Function actualizar(ByVal registro As String) As Integer
Dim myadapter As New MySqlDataAdapter
Dim command As New MySqlCommand command.Connection = con
command.CommandText = registro
myadapter.SelectCommand = command
actualizar = command.ExecuteNonQuery End Function
End Module