CONEXION MYSQL Y ORACLE VB
CONEXION MYSQL Y ORACLE VB
MySqlClient
='';database=prueba")
End Sub
Try
conexion.Open()
Catch ex As MySqlException
MsgBox(ex.Message.ToString)
exito = False
End Try
If exito Then
Dim sql As MySqlCommand = New MySqlCommand
sql.Connection = conexion
sql.CommandText = "INSERT INTO afiliados
(codigo,nombre,direccion,telefono)
VALUES('" &
TextBox1.Text & "','" &
TextBox2.Text & "','" &
TextBox3.Text & "','" &
TextBox4.Text & "')"
sql.CommandType = CommandType.Text
sql.ExecuteReader()
conexion.Close()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button2.Click
Try
conexion.Open()
Catch ex As MySqlException
MsgBox(ex.Message.ToString)
exito = False
End Try
If exito Then
Dim a As Integer
a = Val(TextBox1.Text)
Dim sql As MySqlCommand = New MySqlCommand
sql.Connection = conexion
sql.CommandText = "SELECT * FROM afiliados Where
codigo=" & a & ""
sql.CommandType = CommandType.Text
Dim dr As MySqlDataReader
dr = sql.ExecuteReader()
dr.Read()
If dr.HasRows Then
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
TextBox4.Text = dr(3)
Else
MsgBox("Registro No Encontrado")
End If
conexion.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button3.Click
Try
conexion.Open()
Catch ex As MySqlException
MsgBox(ex.Message.ToString)
exito = False
End Try
If exito Then
Dim da As New MySqlDataAdapter
da.SelectCommand = New MySqlCommand("SELECT * FROM
afiliados", conexion)
Dim dr As New DataTable
da.Fill(dr)
datos.DataSource = dr
conexion.Close()
End If
End Sub
End Class
Imports System.Data.OracleClient
Public Class Form1
Dim con As OracleConnection
Dim exito As Boolean = True
MsgBox(ex.Message)
exito = False
End Try
If (exito) Then
MsgBox("parece")
Dim cmm As OracleCommand = New OracleCommand()
cmm.Connection = con
cmm.CommandText = "INSERT INTO estudianrte (codigo,nombre,edad,curso) VALUES('" +
TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')"
cmm.CommandType = CommandType.Text
cmm.ExecuteReader()
End If
con.Close()
End Sub
If exito Then
Dim a As Integer
a = Val(TextBox1.Text)
Dim sql As OracleCommand = New OracleCommand
sql.Connection = con
sql.CommandText = "SELECT * FROM estudianrte Where codigo=" & a & ""
sql.CommandType = CommandType.Text
Dim dr As OracleDataReader
dr = sql.ExecuteReader()
dr.Read()
If dr.HasRows Then
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
TextBox4.Text = dr(3)
Else
MsgBox("Registro No Encontrado")
End If
con.Close()
End If
End Sub
End Class
Buton1:Guardar
Buton2:Buscar
Buton3:Ver
End Try
If exito Then
Try
Dim sql As MySqlCommand = New MySqlCommand
sql.Connection = conexion
sql.CommandText = "insert Into afiliados
(codigo,nombre,apellido,telefono)VALUES('" & TextBox1.Text & "','" &
TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "' )"
sql.CommandType = CommandType.Text
sql.ExecuteReader()
Catch ex As MySqlException
MsgBox(ex.Message.ToString)
exito = False
End Try
conexion.Close()
End If
End Sub
Para llevar los registros de la tabla a los textbox..
Private Sub Datos_RowEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles Datos.RowEnter
Dim var As Integer
var = e.RowIndex
TextBox1.Text = Datos.Rows(var).Cells(0).Value.ToString()
TextBox2.Text = Datos.Rows(var).Cells(1).Value.ToString()
TextBox3.Text = Datos.Rows(var).Cells(2).Value.ToString()
TextBox4.Text = Datos.Rows(var).Cells(3).Value.ToString()
End Sub