0% found this document useful (0 votes)
81 views4 pages

Database Connection and CRUD Operations

This document contains code for connecting to a database and performing various operations on a database table like inserting, updating, deleting, searching, and filtering records. It defines connection strings and modules for the database connection. It also includes subroutines for saving, modifying, deleting records, generating codes, handling clicks on the data grid view, calculating totals, and moving panels.

Uploaded by

JOSE
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)
81 views4 pages

Database Connection and CRUD Operations

This document contains code for connecting to a database and performing various operations on a database table like inserting, updating, deleting, searching, and filtering records. It defines connection strings and modules for the database connection. It also includes subroutines for saving, modifying, deleting records, generating codes, handling clicks on the data grid view, calculating totals, and moving panels.

Uploaded by

JOSE
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

CONEXIÓN

Imports [Link]
Imports [Link]

Module Conexion
Public CN As New [Link]("Provider=sqloledb;Data Source=.\SQLEXPRESS;initial
catalog=municipalidad;user id=sa ;password=123456")
Public cb As New [Link]("Data source=.\SQLexpress;initial catalog=municipalidad;user
ID=sa;Password=123456")
End Module

Load
[Link] = [Link] * 2

BOTON GUARDAR
Dim modi As Boolean
If modi = True Then
guarda()
modi = False
[Link] = False
Exit Sub
Else
[Link] = False
[Link] = True
modificardata()
End If

INGRESAR REGISTRO
Sub guarda()
Dim QUERY As String
QUERY = "INSERT INTO Registrador_a VALUES ('" & [Link] & "','" &
[Link] & "','" & [Link] & "','" & [Link] & "','" & [Link] &
"','" & [Link] & "','" & [Link] & "','" & [Link] & "','" &
[Link] & "','" & [Link] & "','" & [Link] & "','" &
[Link] & "','" & [Link] & "','" & [Link] & "','" &
[Link] & "','" & [Link] & "','" & [Link] & "','" & [Link] &
"','" & [Link] & "')"
Dim CM As New [Link](QUERY, CN)
[Link]()
[Link]()
MsgBox("Se a Ingresado los datos Correspondientes" & vbCrLf & "Nota:los Nuevos
trabajadores", [Link])
[Link]()
GenerarCodigo()
[Link]()
LIMPIAR()
End Sub

MODIFICAR
Sub modificardata()
Dim c As String
c = "Update Registrador_a set AP_PATERNO='" & [Link] & "',AP_MATERNO='" &
[Link] & "',NOMBRE='" & [Link] & "',DNI='" & [Link] & "',FECHA_NAC='" &
[Link] & "',SEXO='" & [Link] & "',ESTADO_CIV='" & [Link] &
"',N_HIJOS='" & [Link] & "',mes='" & [Link] & "',FECHA_ING='" &
[Link] & "',FECHA_Cese='" & [Link] & "',DIRECCION='" &
[Link] & "',AREA='" & [Link] & "',DESCRIPCION='" & [Link] &
"',OCUPACION='" & [Link] & "',PROFECION='" & [Link] & "',TELEFONO='" &
[Link] & "',CELULAR='" & [Link] & "' WHERE ID_Registro='" & [Link] &
"'"
[Link]()
Dim CMD As New [Link](c, CN)
MsgBox("Se A Modificado Los Datos" & vbCrLf & "Nota: Del trabajador",
[Link])
[Link]()
[Link]()
End Sub
Eliminar
Dim message As String
message = [Link]("Desea eliminar el registro", "ADVERTENCIA",
[Link], [Link])
If message = vbYes Then
Dim c As String
c = "DELETE FROM Registrador_a WHERE ID_Registro='" & [Link] & "'"
[Link]()
Dim CMD As New [Link](c, CN)
[Link]()
MsgBox("Se a Eliminado de la Base de datos" & vbCrLf & "Nota:A Un trabajador",
[Link])
[Link]()
[Link]()
LIMPIAR()
End If

Buscar
Dim dt As New DataTable
Dim C As String
C = "select * from Registrador_a where ID_Registro='" & [Link] & "'"
Dim da As New [Link](C, CN)
[Link](dt)
If [Link] > 0 Then
Dim dr As DataRow = [Link](0)
[Link] = dr(1)
[Link] = dr(2)

[Link] = True
[Link] = True
[Link] = False
[Link] = True

Exit Sub
Else

[Link] = False
[Link] = False
[Link] = True
[Link] = False

End If

Buscar filtrar
Dim DTS As New DataSet
Sub BUSCAREMPLEADO()
Try
Dim CL As New [Link]("SELECT ID_Registro,(ap_paterno + ' ' +
ap_materno + ' ' + nombre)AS [ APELLIDOS Y NOMBRES],dni,sexo,OCUPACION FROM
Registrador_a WHERE (ap_paterno + ' ' + ap_materno + ' ' + nombre) LIKE'" & [Link] &
"%'", CN)
[Link](DTS, 0)
[Link] = [Link](0)
[Link]()
With DataGridView1
.Columns(0).HeaderText = "CODIGO"
.Columns(0).Width = "70"
.Columns(1).Width = "300"
.Columns(2).HeaderText = " DNI"
.Columns(2).Width = "70"
.Columns(3).HeaderText = " SEXO"
.Columns(3).Width = "70"
.Columns(4).HeaderText = " OCUPACION"
.Columns(4).Width = "289"
End With
Catch ex As Exception
MsgBox([Link])
End Try
End Sub

Generar código
Dim codS As New DataTable
Sub GenerarCodigo()
Dim da As New [Link]("SELECT * FROM Registrador_a", CN)
[Link](codS)
Dim extra, c As String
If [Link] = 0 Then
c = "N° 000001"
[Link] = c
Else
c = [Link]([Link] - 1)("ID_Registro").ToString
extra = Str(Val([Link](5, 5)) + 1000001)
[Link] = "N° " + [Link](2, 6)
End If
End Sub

DataGridView

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As


[Link]) Handles [Link]
[Link] = [Link](0, [Link]).Value
[Link] = [Link](1, [Link]).Value
[Link] = False
modi = False
End Sub

Sumar datagrid

Public Function calcular(ByVal nombre_Columna As String, ByVal Dgv As DataGridView) As


Double
Dim total As Double = 0
Try
For i As Integer = 0 To [Link] - 1
total = total + CDbl([Link](nombre_Columna.ToLower, i).Value)
Next
Catch ex As Exception
MsgBox([Link])
End Try
Return total
End Function

Sub SUMARCOLUMNA()

If [Link] >= 1 Then

Dim numero As Integer = [Link]


Dim impor As Double = [Link]("Importe", DataGridView7).ToString()

[Link] = Format(impor, "###.00")

[Link] = True

Else

[Link] = "0.00"

[Link] = False

End If

End Sub

Dim xr As Integer : Dim yr As Integer


Private Sub Mueve(ByVal opcion As Integer, ByVal objeto As Control, ByVal e As
[Link])
If opcion = 0 Then
xr = e.X
yr = e.Y
Else
If [Link] = [Link] Then
[Link] = New Point([Link] + e.X - xr, [Link] + e.Y - yr)
End If
End If
End Sub

Private Sub Panel2_MouseDown(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
Mueve(0, Panel2, e)
End Sub
Private Sub Panel2_MouseMove(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
Mueve(1, Panel2, e)
End Sub

[Link]("nombrecolumna").[Link] = "HH:mm"

You might also like