Public Class Form1
Dim connString As String = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
& "D:\PRACTICA MI_BASE\Mi_base.accdb" & ";Persist Security Info=False;") 'CAMBIA LA RUTA
Dim Conexión As OleDbConnection = New OleDbConnection
Private Sub SujetoBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.SujetoBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Mi_baseDataSet)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: esta línea de código carga datos en la tabla 'Mi_baseDataSet.Sujeto' Puede moverla o quitarla según sea necesario.
Me.SujetoTableAdapter.Fill(Me.Mi_baseDataSet.Sujeto)
End Sub
Private Sub Nuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nuevo.Click
Try
CedulaTextEdit.Text = ""
NombresTextEdit.Text = " "
EdadTextEdit.Text = 0
SexoTextEdit.Text = ""
CedulaTextEdit.Select()
Catch ex As Exception
ex.Message.ToUpper()
End Try
End Sub
Private Sub Guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Guardar.Click
'Abrimos la conexión
Conexión.ConnectionString = connString
Conexión.Open()
'Guardamos solo 4 campos
Dim str As String
str = "insert into Sujeto ([Cedula], [Nombres], [Edad], [Sexo]) values (?, ?, ?, ?)"
Dim cmd As OleDbCommand = New OleDbCommand(str, Conexión)
cmd.Parameters.Add(New OleDbParameter("Cedula", CType(CedulaTextEdit.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Nombres", CType(NombresTextEdit.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Edad", CType(EdadTextEdit.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Sexo", CType(SexoTextEdit.Text, String)))
Try
cmd.ExecuteNonQuery()
MsgBox("La información se guardo correctamente..!", MsgBoxStyle.Information, "Registro de usuarios")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Me.SujetoTableAdapter.Fill(Me.Mi_baseDataSet.Sujeto)
Conexión.Close()
End Sub
Private Sub Eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Eliminar.Click
If SujetoDataGridView.Rows.Count < 1 Then Exit Sub
If MsgBox("Deseas eliminar el registro?", CType(vbQuestion + vbYesNo, MsgBoxStyle), _
"Eliminar registro") = vbNo Then Exit Sub
Conexión.ConnectionString = connString
Conexión.Open()
Dim str As String
str = "Delete from Sujeto Where Cedula = '" & CedulaTextEdit.Text & "'"
Dim cmd As OleDbCommand = New OleDbCommand(str, Conexión)
Me.SujetoTableAdapter.Fill(Me.Mi_baseDataSet.Sujeto)
Try
cmd.ExecuteNonQuery()
MsgBox("Registro eliminado", MsgBoxStyle.Exclamation, "Eliminar registro")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Me.SujetoTableAdapter.Fill(Me.Mi_baseDataSet.Sujeto)
Conexión.Close()
End Sub
End Class
0 comentarios:
Publicar un comentario