Foros del Web » Programación para mayores de 30 ;) » .NET »

conecta bd mysql con visual .net

Estas en el tema de conecta bd mysql con visual .net en el foro de .NET en Foros del Web. hola chicos como estas, les cuento q estoy comenzandoa utilizar mysql conjuntamente con .net, ya q es una exigencia de nuestra facu para realizar una ...
  #1 (permalink)  
Antiguo 09/11/2007, 09:01
 
Fecha de Ingreso: noviembre-2007
Mensajes: 1
Antigüedad: 16 años, 6 meses
Puntos: 0
conecta bd mysql con visual .net

hola chicos como estas, les cuento q estoy comenzandoa utilizar mysql conjuntamente con .net, ya q es una exigencia de nuestra facu para realizar una apliccacion, y mi problema es el sig:
* esta es el codigo q tengo
Imports System.Data
Imports System.Data.Odbc
Imports System
Imports System.IO



Public Class formMenuPrincipal
Public conexionBD As OdbcConnection

Private Sub bConectar_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles bConectar.Click
Try
If (txtMotor.Text = "MySQL") Or (txtMotor.Text = "") Then
conexionBD = New OdbcConnection("dsn=localhost" & _
txtODBC.Text & ";uid=MySQL ODBC 3.51 Driver" & _
TxtUsuario.Text & ";pwd=root" & _
txtContrasena.Text & "floresgump")
End If

conexionBD.Open()
lInfo.Text = "Conectado correctamente"
bDesconectar.Enabled = True
bEjecutar.Enabled = True

Catch ex As OdbcException
lInfo.Text = "Error en la conexión"
bDesconectar.Enabled = False
bEjecutar.Enabled = False
MsgBox(ex.Message)
End Try
End Sub

Private Sub bDesconectar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bDesconectar.Click
Try
conexionBD.Close()
lInfo.Text = "Desconectado correctamente"
Catch ex As OdbcException
'silenciosa
lInfo.Text = "Desconectado correctamente"
End Try

End Sub

Private Sub bGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bGuardar.Click
Dim dlAbrir As New _
System.Windows.Forms.SaveFileDialog

dlAbrir.Filter = "Archivos de Texto (*.txt)|*.txt|" & _
"Archivos de SQL (*.sql)|*.sql|" & _
"Todos los archivos (*.*)|*.*"
dlAbrir.CheckFileExists = False
dlAbrir.OverwritePrompt = True
dlAbrir.Title = "Guardar SQL en fichero"
dlAbrir.ShowDialog()
If dlAbrir.FileName <> "" Then
Dim fichero As New _
System.IO.StreamWriter(dlAbrir.FileName)
fichero.WriteLine(txtSQL.Text)
fichero.Close()
End If

End Sub

Private Sub bCargar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bCargar.Click
Dim dlAbrir As New _
System.Windows.Forms.OpenFileDialog

dlAbrir.Filter = "Archivos de Texto (*.txt)|*.txt|" & _
"Archivos de SQL (*.sql)|*.sql|" & _
"Todos los archivos (*.*)|*.*"
dlAbrir.CheckFileExists = False
dlAbrir.Multiselect = False
dlAbrir.Title = "Abrir fichero SQL"
dlAbrir.ShowDialog()
If dlAbrir.FileName <> "" Then
Dim fichero As New _
System.IO.StreamReader(dlAbrir.FileName)
txtSQL.Text = fichero.ReadToEnd()
fichero.Close()
End If

End Sub

Private Sub bEjecutar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bEjecutar.Click
Try
Dim sql As String = txtSQL.Text
Dim comandoSQL As OdbcCommand = _
New OdbcCommand(sql, conexionBD)
Dim resultadoSQL As OdbcDataReader = _
comandoSQL.ExecuteReader()
Dim i As Integer


txtResultado.Clear()
'Ponemos una fila con el nombre de los campos

For i = 0 To resultadoSQL.FieldCount - 1
If txtResultado.Text <> "" Then
txtResultado.Text = txtResultado.Text & _
Chr(9) & resultadoSQL.GetName(i)
Else
txtResultado.Text = resultadoSQL.GetName(i)
End If
Next i

While resultadoSQL.Read
txtResultado.Text = txtResultado.Text & _
Chr(13) & Chr(10)
For i = 0 To resultadoSQL.FieldCount - 1
If i = 0 Then
txtResultado.Text = txtResultado.Text & _
resultadoSQL(i).ToString
Else
txtResultado.Text = txtResultado.Text & _
Chr(9) & resultadoSQL(i).ToString
End If
Next i
End While

Catch ex As OdbcException
MsgBox(ex.Message)
End Try

End Sub

Private Sub bGuardarResultado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bGuardarResultado.Click
Dim dlAbrir As New _
System.Windows.Forms.SaveFileDialog

dlAbrir.Filter = "Archivos de texto (*.txt)|*.txt|" & _
"Todos los archivos (*.*)|*.*"
dlAbrir.CheckFileExists = False
dlAbrir.OverwritePrompt = True
dlAbrir.Title = "Guardar resultado ejecución SQL"
dlAbrir.ShowDialog()
If dlAbrir.FileName <> "" Then
Dim fichero As New _
System.IO.StreamWriter(dlAbrir.FileName)
fichero.WriteLine(txtResultado.Text)
fichero.Close()
End If

End Sub

Private Sub bSeleccionarTodo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bSeleccionarTodo.Click
txtResultado.SelectAll()

End Sub

Private Sub bCopiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bCopiar.Click
txtResultado.Copy()

End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSQL.TextChanged

End Sub
End Class

la generacion es satisfactoria hasta q intento realizar la conexion
ERROR(IM002)(MICROSOFT)(ADMINISTRADOR DE CONTROLADORES ODBC) NO SE ENCUENTRA EL NOMBRE DE ORIGEN Y NO SE ESPECIFICO NINGUN CONTROLADOR PREDETERMINADO.
YO TENGO INSTALADO MYSQL ODBC 3.51 DRIVES PARA Q ME CONECTE LA BASE DE DATOS-
POR FAVOR AYUDENME. GRACIAS
  #2 (permalink)  
Antiguo 09/11/2007, 13:29
 
Fecha de Ingreso: marzo-2007
Ubicación: En El salvador
Mensajes: 78
Antigüedad: 17 años, 1 mes
Puntos: 0
Re: conecta bd mysql con visual .net

Primeramente, porque no consigues algun conector hecho para trabajar con MySQL? no es que no se pueda de ese modo, pero se te haria más facil, por ejemplo usando MySQL Connector/Net, el sitio donde puedes encontrar lo necesario es el siguiente:

http://www.mysql-hispano.org/page.php?id=41&pag=1
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:50.