Este documento presenta fragmentos de código para agregar y guardar registros nuevos en una base de datos. El primer fragmento de código verifica si existe un registro duplicado antes de agregar un nuevo registro. Si no existe un duplicado, agrega una nueva fila y establece los campos. El segundo fragmento de código guarda los cambios en la base de datos cuando se hace clic en el botón "Grabar" y deshabilita los campos de texto.
1. COLEGIO DE EDUCACION PROFESIONAL
TECNICA DEL ESTADO DE TLAXCALA
Alumno:
TECPA SÀNCHEZ WILLIAN
Docente: ING. AGUSTÌN HERNÀNDEZ DELGADO
PROYECTO:(CODREP)CONTROL DE REPORTES
MODULO: ELABORACIÒN Y MANTENIMIENTO DE SISTEMAS DE
INFORMACIÒN
ESPECIALIDAD: INFORMÀTICA
GRADO: 6º SEMESTREGRUPO: 606
2. Este es el código que busca y da de alta un nuevo registro
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim mitabla As DataTable = ControlDeReportesDataSet.Altas
Dim cfilas As DataRowCollection = mitabla.Rows
Dim nuevafila As DataRow
Dim i As Integer
Dim bandera As Boolean
bandera = True
Dim tamano As Integer
AltasBindingSource.MoveFirst()
tamano = AltasBindingSource.Count()
Dim res As Boolean
Dim a As String
Dim b As String
a = UCase(Trim(MatriculaTextBox.Text))
b = UCase(Trim(TextBox1.Text))
If (tamano = 0) Then
MsgBox("Tabla Vacia")
Else
AltasBindingSource.MoveFirst()
a = UCase(Trim(MatriculaTextBox.Text))
Do
res = a Like b
If (res = True) Then
bandera = False
Else
AltasBindingSource.MoveNext()
a = UCase(Trim(MatriculaTextBox.Text))
i = i + 1
End If
Loop While (bandera = True And i <= tamano)
End If
If (bandera = False) Then
MatriculaTextBox.Visible = True
NombreTextBox.Visible = True
ApellidoTextBox.Visible = True
4. Este es el código del botón grabar
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If (ControlDeReportesDataSet.HasChanges) Then
Me.Validate()
Me.AltasBindingSource.EndEdit()
Me.AltasTableAdapter.Update(Me.ControlDeReportesDataSet.Altas)
MsgBox("Grabado")
MatriculaTextBox.Enabled = False
NombreTextBox.Enabled = False
ApellidoTextBox.Enabled = False
EspecialidadTextBox.Enabled = False
GrupoTextBox.Enabled = False
TurnoTextBox.Enabled = False
End If
End Sub