Programación Formulario De Registro Y Busqueda Vb.Net-Mysql
DECLARACION VARABLES PÚBLICAS
Public Class Form1
Dim cnn As MySQLDriverCS.MySQLConnection
REALIZAR CONEXION EN EL LOAD DEL FORMULARIO
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'***************************Realizar Conexión**********************************************
Dim myConString AsNew MySQLDriverCS.MySQLConnectionString("servidor", "bd", "usuario", "contraseña")
cnn = New MySQLDriverCS.MySQLConnection(myConString.AsString)
cnn.Open()
'******************************************************************************************
End Sub
BOTON GUARDAR
Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnguardar.Click'***************Decraro variables y caoturo la informacion de mis objetos******************
Dim cod, nom, valor As String
cod = txtcodigo.Text
valor = txtapellido.Text
nom = txtnombre.Text
'********Valido que los datos requeridos (Codigo) tengal algun contenido*************
If cod = "" Then
MsgBox("Digite el Codigo",MsgBoxStyle.Information, "Almacenamiento")
Exit Sub
End If
'************************************************************************************
'*************** Escribo el codigo para guardar**************************************
Dim comando As New MySQLDriverCS.MySQLCommand
comando.Connection = cnn
comando.CommandType = CommandType.StoredProcedurecomando.CommandText = "INSERT INTO datos VALUES ('" & cod & "','" & nom & "','" & valor & "')"
comando.ExecuteNonQuery()
MsgBox("DATOS INGRESADOS CORRECTAMENTE", MsgBoxStyle.Information, "REGISTRO")
txtcodigo.Text = ""
txtnombre.Text = ""
txtapellido.Text = ""
End Sub
BOTON BUSQUEDA INDIVIDUAL
Private Sub btnbuscar_Click(ByVal sender AsSystem.Object, ByVal e As System.EventArgs) Handles btnbuscar.Click
Dim bus As String
Dim comando2 As New MySQLDriverCS.MySQLCommand
bus = txtbusqueda.Text
comando2.Connection = cnn
comando2.CommandType = CommandType.StoredProcedure
comando2.CommandText = "SELECT * FROM datos WHERE codigo ='" & bus & "'"
Dim dr As System.Data.IDataReader
dr =comando2.ExecuteReader()
While dr.Read()
txtcodigo.Text = dr("codigo")
txtnombre.Text = dr("nombre")
txtapellido.Text = dr("valor")
End While
End Sub
BOTON MODIFICAR
Private Sub btnmodificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodificar.Click
'***************Decraro variables y caoturo lainformacion de mis objetos******************
Dim bus, nom, ape As String
bus = txtbusqueda.Text
ape = txtapellido.Text
nom = txtnombre.Text
'********Valido que los datos requeridos (Codigo) tengal algun contenido*************
If nom = "" Then
MsgBox("Digite el Nombre", MsgBoxStyle.Information, "Almacenamiento")
Exit SubEnd If
'*************** Escribo el codigo para modificar**************************************
Dim comando4 As New MySQLDriverCS.MySQLCommand
comando4.Connection = cnn
comando4.CommandType = CommandType.StoredProcedure
comando4.CommandText = "UPDATE datos SET nombre = '" & nom & "', apellido = '" & valor & "' WHERE codigo='" & bus & "'"comando4.ExecuteNonQuery()
MsgBox("DATOS MODIFICADOS CORRECTAMENTE", MsgBoxStyle.Information, "MODIFICACIÓN")
txtcodigo.Text = ""
txtnombre.Text = ""
txtapellido.Text = ""
End Sub
BOTON CANCELAR O BORRAR
Private Sub btncancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancelar.Click
txtcodigo.Text = ""...
Regístrate para leer el documento completo.