Retroceder   Foros del Web > Programación para sitios web > .NET

Respuesta
 
Herramientas Desplegado
Antiguo 09-nov-2007, 08:01   #1 (permalink)
napael ha deshabilitado el karma
 
Fecha de Ingreso: noviembre-2007
Mensajes: 1
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
napael está desconectado   Responder Citando
Antiguo 09-nov-2007, 12:29   #2 (permalink)
0skar no se puede cailificar en este momento
 
Fecha de Ingreso: marzo-2007
Ubicación: En El salvador
Mensajes: 75
Enviar un mensaje por MSN a 0skar
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
0skar está desconectado   Responder Citando
Respuesta

No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 18:41.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93