0% found this document useful (0 votes)
36 views3 pages

Imports System

The document contains code for a form that allows users to search for, add, modify, and delete employee records from a SQL database. The form includes text boxes to display employee ID, name, address and other fields. Buttons allow the user to search for a record using the ID, add a new record, modify an existing record, or delete a selected record. The code opens a SQL connection, builds SQL queries based on the button clicked and form field values, executes the queries, and handles validation and error messages.

Uploaded by

Menelio Pineda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Imports System

The document contains code for a form that allows users to search for, add, modify, and delete employee records from a SQL database. The form includes text boxes to display employee ID, name, address and other fields. Buttons allow the user to search for a record using the ID, add a new record, modify an existing record, or delete a selected record. The code opens a SQL connection, builds SQL queries based on the button clicked and form field values, executes the queries, and handles validation and error messages.

Uploaded by

Menelio Pineda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Buscar

Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
If TxtId.Text = "" Then
MsgBox("Ingrese un ID para Buscar", MsgBoxStyle.Exclamation, "Falta
Datos")
TxtId.Focus()
Exit Sub

End If
Con.Open()
comando = "select * from empleados where Id='" & TxtId.Text & "'"
consulta = New SqlCommand(comando, Con)
dr = consulta.ExecuteReader
If dr.Read Then
TxtNombre.Text = dr(1)
TxtApellido.Text = dr(2)
TxtDireccion.Text = dr(3)
TxtCiudad.Text = dr(4)
TxtTelefono.Text = dr(5)
TxtEstado.Text = dr(6)
BtnModiicar.Enabled = True
BtnEliminar.Enabled = True
Con.Close()
Else
MsgBox("No existe Registro con ese ID", MsgBoxStyle.Exclamation, "Sin
Resultados")
Call Limpiar()

BtnModiicar.Enabled = False
BtnEliminar.Enabled = False
TxtId.Focus()

End If
Con.Close()
End Sub

Guardar
If TxtId.Text = "" Then
MsgBox("Ingrese un ID para Buscar", MsgBoxStyle.Exclamation, "Falta
Datos")
TxtId.Focus()
Exit Sub

End If
Con.Open()
comando = "select * from empleados where Id='" & TxtId.Text & "'"
consulta = New SqlCommand(comando, Con)
dr = consulta.ExecuteReader
If dr.Read Then
MsgBox("Este Registro ya Existe", MsgBoxStyle.Information,
"Atencion")
Call Limpiar()
Con.Close()
Else
dr.Close()
comando = "insert into
empleados(Id,nombre,Apellido,Direccion,Ciudad,Telefon,Estadocivil) values ('" &
TxtId.Text & "','" & TxtNombre.Text & "','" & TxtApellido.Text & "','" &
TxtDireccion.Text & "','" & TxtCiudad.Text & "','" & TxtTelefono.Text & "','" &
TxtEstado.Text & "')"
guardar = New SqlCommand(comando, Con)
guardar.ExecuteNonQuery()
MsgBox("Registro Guardado Exitoosamente", MsgBoxStyle.Exclamation,
"Registro Guardado")
Call Limpiar()
Con.Close()

End If

Modificar

Con.Open()
comando = "update empleados set nombre='" & TxtNombre.Text &
"',Apellido='" & TxtApellido.Text & "',Direccion='" & TxtDireccion.Text &
"',Ciudad='" & TxtCiudad.Text & "',Telefon='" & TxtTelefono.Text &
"',Estadocivil='" & TxtEstado.Text & "' where Id='" & TxtId.Text & "'"
modificar = New SqlCommand(comando, Con)
modificar.ExecuteNonQuery()
MsgBox("Registro Actualizado con Exitoo", MsgBoxStyle.Exclamation,
"Registro Actualizado")
Call Limpiar()
Con.Close()

Modificar
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
BtnModiicar.Click
Con.Open()
comando = "update empleados set nombre='" & TxtNombre.Text &
"',Apellido='" & TxtApellido.Text & "',Direccion='" & TxtDireccion.Text &
"',Ciudad='" & TxtCiudad.Text & "',Telefon='" & TxtTelefono.Text &
"',Estadocivil='" & TxtEstado.Text & "' where Id='" & TxtId.Text & "'"
modificar = New SqlCommand(comando, Con)
modificar.ExecuteNonQuery()
MsgBox("Registro Actualizado con Exitoo", MsgBoxStyle.Exclamation,
"Registro Actualizado")
Call Limpiar()
Con.Close()
End Sub
Eliminar
Con.Open()
Dim respuesta As String
respuesta = MsgBox("Segururo desea eliminar el Registro Seleccioonado",
vbYesNo, "Eliminacion de Registro")
If respuesta = vbYes Then
comando = "delete from empleados where Id='" & TxtId.Text & "'"
eliminar = New SqlCommand(comando, Con)
eliminar.ExecuteNonQuery()
MsgBox("Registro Eliminado con Exitoo", MsgBoxStyle.Exclamation,
"Registro Eliminado")
Call Limpiar()
Else
MsgBox("Operacioon Cancelada por el Usuario",
MsgBoxStyle.Exclamation, "Cancelado")
BtnModiicar.Enabled = False
BtnEliminar.Enabled = False
Call Limpiar()

End If
Con.Close()

You might also like