Auditoria Informatica
Imports MySql.Data.MySqlClient ENTER
Public Class CConexion
Private _cadena As String
Private _conexion As MySqlConnection
Private _tabla As New DataTable
Private _adaptador As New MySqlDataAdapter
Private Sub conexion() agregamos un nuevo origen de datos.
_cadena = "server=localhost;UserId=root;password=1234;Persist Security Info=True;database=ejemplo"
_conexion = New MySqlConnection(_cadena)
End Sub
Public Function consultar_todos() As Boolean
Dim estado As Boolean = True
Try
conexion()
_adaptador.SelectCommand = New MySqlCommand("Select * from por_tu_culpa", _conexion)
_adaptador.Fill(_tabla)
Catch ex As MySqlExceptionestado = False
Finally
cerrar()
End Try
Return estado
End Function
Private Sub cerrar()
_conexion.close()
End Sub
End Class
DESPUES NOS VAMOS A LA PARTE DEL DISEÑO, Y RENOMBRAMOS EL FORMULARIO DataGridView1 POR DGDatos. Luego doble clic al formulario de a fuera y nos aparece el from load ahí insertamos el sig. Código:debajo del private sub form1_load
Dim conexion As New CConexion
Dim tabla As New DataTable
Nos vamos a la CConexion y insertamos el sig. codigo; abajo del end funtion.
Public Function tabla() As DataTable
seguido de este codigo tambien
Return _tabla
nos vamos al form1 y insertamos este codigo debajo de los dim:
If conexion.consultar_todos Then
tabla= conexion.tabla
DGDatos.DataSource = tabla
Else
MessageBox.Show("No se pudieron consultar los datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
y ahora lo corremos.
ya q nos mostro la tabla, nos vamos al mysql y insertamos otro dato y tiene q aparecer en visual tambien.
nos vamos a las propiedades del datagrid y le decimos q nomidifique la tabla.
tru, false, false,false, false y false.
Y también le decimos q es de solo lectura en el ReadOnly poniéndole True. a hi mismo
Luego agregamos los label y txtBox correspondientes.luego nos vamos al código del dataGrid y donde tenemos el cellContenClick lo cambiamos por el SelectionChanged.
ya que cambio nos vamos a nuestro diseño y le ponemos nombre a nuestras variables“texBox” que serian:
txtidmatricula, txtnombre, txtprimer_apellido, txtedad, txtcurp.
Después nos vamos al form1 donde dice selctionchanged y insertamos el siguiente código:
txtidmatricula.Text = DGDatos.Rows(DGDatos.CurrentRow.Index).Cells(0).Value
txtnombre.Text = DGDatos.Rows(DGDatos.CurrentRow.Index).Cells(1).Value
txtprimer_apellido.Text =DGDatos.Rows(DGDatos.CurrentRow.Index).Cells(2).Value
txtedad.Text = DGDatos.Rows(DGDatos.CurrentRow.Index).Cells(3).Value
txtcurp.Text= DGDatos.Rows(DGDatos.CurrentRow.Index).Cells(4).Value
Despues nos vamos al diseño y seleccionamos los texBox le cambiamos el RedOnly a True. A si hevitamos q puedan acceder al sistema.
Despues insertamos los botones correspondientes,
Nuevo,Grabar,Actualizar Y Eliminar.
Luegole ponemos un identificador para poderlos encontrar en el name=
btnnuevo, btngrabar,btnactualizar y btneliminar.
Despues le agregamos el sigueente codigo al boton nuevo;
txtidmatricula.Text = ""
txtnombre.Text = ""
txtprimer_apellido.Text = ""
txtedad.Text = ""
txtcurp.Text = ""
txtidmatricula.ReadOnly = False
txtnombre.ReadOnly = Falsetxtprimer_apellido.ReadOnly = False
txtedad.ReadOnly = False
txtcurp.ReadOnly = False
lo corremos y miramos q ya te funciona el boton nuevo.
de a hi agregamos una nueva clase que nos va aservir para encapsular todala imformacion y se llamara CDatos.
Dentro de ella ponelas las siguientes variables abajo del public class CDatos;
Private _idmatricula As Integer...
Regístrate para leer el documento completo.