Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Practica 17 - BD con MySQL
- Imports MySql.Data.MySqlClient
- Public Class Form1
- 'Friend conexion As MySqlConnection
- Dim servidor As String
- Dim usuario As String
- Dim pswd As String
- Dim myData As New DataSet
- Dim conn As New MySqlConnection
- Dim myConnectionString As String
- Dim intCurrentIndex As Integer = 0
- ' Dim cmd As New MySqlCommand
- 'Dim conn As New MySql.Data.MySqlClient.MySqlConnection
- Private Sub cmdTestConexion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTestConexion.Click
- REM Try
- REM servidor = ""
- REM usuario = ""
- REM pswd = ""
- REM conexion = New MySqlConnection()
- REM conexion.ConnectionString = "server=" & servidor & ";" & "user id=" & usuario & ";" & "password=" & pswd & ";"
- REM conexion.Open()
- REM MessageBox.Show("Conectado al servidor")
- REM Catch ex As MySqlException
- REM MessageBox.Show("No se ha podido conectar al servidor")
- REM End Try
- myConnectionString = "server=192.168.1.80;" & "uid=seriel;" & "pwd=frodo;" & "database=amigos;"
- Try
- conn.ConnectionString = myConnectionString
- conn.Open()
- MessageBox.Show("Conectado al Servidor")
- conn.Close()
- Catch ex As MySql.Data.MySqlClient.MySqlException
- ' MessageBox.Show(ex.Message)
- Select Case ex.Number
- Case 0
- MessageBox.Show("No se puede conectar al servidor. Contacte al Administrador")
- Case 1045
- MessageBox.Show("Usuario/password invalido, por favor intente otra vez")
- End Select
- End Try
- End Sub
- Private Sub cmdLlenar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLlenar.Click
- myConnectionString = "server=192.168.1.80;" & "uid=seriel;" & "pwd=frodo;" & "database=amigos;"
- conn.ConnectionString = myConnectionString
- 'Dim id_puntero As Integer
- 'id_puntero = InputBox("Indicar id")
- REM Dim x As String
- conn.Open()
- 'cmd.CommandText = "SELECT nombre FROM amigos"
- 'cmd.Connection = conn
- 'La consulta de la línea anterior debe devolver únicamente un registro
- Dim cmd As New MySqlCommand("SELECT * from contacto", conn)
- Dim myAdapter As New MySqlDataAdapter(cmd)
- myAdapter.Fill(myData)
- txtNombre.Text = myData.Tables(0).Rows(0).Item("nombre").ToString
- txtTelefono.Text = myData.Tables(0).Rows(0).Item("telefono").ToString
- txtDireccion.Text = myData.Tables(0).Rows(0).Item("direccion").ToString
- End Sub
- Private Sub cmdSiguiente_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSiguiente.Click
- If intCurrentIndex < myData.Tables(0).Rows.Count - 1 Then
- intCurrentIndex = intCurrentIndex + 1
- txtNombre.Text = myData.Tables(0).Rows(intCurrentIndex).Item("nombre").ToString
- txtTelefono.Text = myData.Tables(0).Rows(intCurrentIndex).Item("telefono").ToString
- txtDireccion.Text = myData.Tables(0).Rows(intCurrentIndex).Item("direccion").ToString
- Else
- MessageBox.Show("Ya esta en el ultimo registro")
- End If
- End Sub
- Private Sub cmdSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSalir.Click
- conn.Close()
- End
- End Sub
- Private Sub cmdAnterior_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAnterior.Click
- If intCurrentIndex > 0 Then
- intCurrentIndex = intCurrentIndex - 1
- txtNombre.Text = myData.Tables(0).Rows(intCurrentIndex).Item("nombre").ToString
- txtTelefono.Text = myData.Tables(0).Rows(intCurrentIndex).Item("telefono").ToString
- txtDireccion.Text = myData.Tables(0).Rows(intCurrentIndex).Item("direccion").ToString
- Else
- MessageBox.Show("Ya esta en el primer registro")
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement