Visual Basic - Conexión con base de datos

Life is soft - evento anual de software empresarial
 
Vista:

Conexión con base de datos

Publicado por ivan (29 intervenciones) el 27/08/2008 01:19:08
hola:

Alguien me puede ayudar a hacer una conexión a una base de datos mysql que esta en un dominio?

Lo que necesito es coger los datos de un excel y subirlo al la base de datos.

Necesitaría saber como hacer la conexión, leer datos, insertar y eliminar.

Gracias de antemano
Iván
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Conexión con base de datos

Publicado por pacopaz (173 intervenciones) el 27/08/2008 01:30:13
Necesitarás el driver de conexión a MySql, pero una vez que lo tengas, puedes implementar un conection string de forma muy sencilla para crear dicha conexión.
Aquí la referencia:
http://www.connectionstrings.com/?carrier=mysql

Driver:
http://dev.mysql.com/downloads/connector/odbc/5.1.html

Espero que te sirva.

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Conexión con base de datos

Publicado por ivan (29 intervenciones) el 27/08/2008 10:47:13
Hola:

Gracias por contestar, pero tengo un problema, no se crear la conection string. Donde tengo que poner los parametros que me has indicado en la web?

Un saludo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Conexión con base de datos

Publicado por pacopaz (173 intervenciones) el 27/08/2008 16:47:17
Entonces lo que tu necesitas es todo el proceso de utilización de la base de datos y no sólo la forma de conectarte.
Esto puede servir para que te des una idea:
http://www.timesheetsmts.com/adotutorial.htm

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Conexión con base de datos

Publicado por ivan (29 intervenciones) el 27/08/2008 18:58:07
Hola Paco:

Estoy siguiendo tus instrucciones y no me hago con ello.

En la web que me has dicho viene un ejemplo que funciona muy bien para acces y en local pero no consigo hacerle funcionan en el sql que tengo en mi dominio.

Este es el codigo, y solo tienen un command.

Private Sub Command1_Click()
'
'Define the three objects that we need,
' A Connection Object - connects to our data source
' A Command Object - defines what data to get from the data source
' A RecordSet Object - stores the data we get from our data source
'
Dim conConnection As New ADODB.Connection
Dim cmdCommand As New ADODB.Command
Dim rstRecordSet As New ADODB.Recordset

'
'Defines the connection string for the Connection. Here we have used fields
'Provider, Data Source and Mode to assign values to the properties
' conConnection.Provider and conConnection.Mode
'
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "" & "database.mdb;Mode=Read|Write"

'
'Define the location of the cursor engine, in this case we are opening an Access database
'and adUseClient is our only choice.
'
conConnection.CursorLocation = adUseClient

'
'Opens our connection using the password "Admin" to access the database. If there was no password
'protection on the database this field could be left out.
'
conConnection.Open

'
'Defines our command object
'
' .ActiveConnection tells the command to use our newly created command object.
' .CommandText tells the command how to get the data, in this case the command
' will evaluate the text as an SQL string and we will return all
' records from a table called tabTestTable
' .CommandType tells the command to evaluate the .CommandText property as an SQL string.
'
With cmdCommand
.ActiveConnection = conConnection
.CommandText = "SELECT * FROM tabTestTable;"
.CommandType = adCmdText
End With
'
'Defines our RecordSet object.
'
' .CursorType sets a static cursor, the only choice for a client side cursor
' .CursorLocation sets a client side cursor, the only choice for an Access database
' .LockType sets an optimistic lock type
' .Open executes the cmdCommand object against the data source and stores the
' returned records in our RecordSet object.
'
With rstRecordSet
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open cmdCommand
End With
'
'Firstly test to see if any records have been returned, if some have been returned then
'the .EOF property of the RecordSet will be false, if none have been returned then the
'property will be true.
'
If rstRecordSet.EOF = False Then
'
'Move to the first record
'
rstRecordSet.MoveFirst
'
'Lets move through the records one at a time until we reach the last record
'and print out the values of each field
'
Do
'
'Access the field values using the fields collection and print them to a message box.
'In this case I do not know what you might call the columns in your database so this
'is the safest way to do it. If I did know the names of the columns in your table
'and they were called "Column1" and "Column2" I could reference their values using:
'
' rstRecordSet!Column1
' rstRecordSet!Column2
'
'
MsgBox "Record " & rstRecordSet.AbsolutePosition & " " & _
rstRecordSet.Fields(0).Name & "=" & rstRecordSet.Fields(0) & " " & _
rstRecordSet.Fields(1).Name & "=" & rstRecordSet.Fields(1)
'
'Move to the next record
'
rstRecordSet.MoveNext
Loop Until rstRecordSet.EOF = True
'
'Add a new record
'
With rstRecordSet
.AddNew
.Fields(0) = "New"
.Fields(1) = "Record"
.Update
End With
'
'Move back to the first record and delete it
'
rstRecordSet.MoveFirst
rstRecordSet.Delete
rstRecordSet.Update

'
'Close the recordset
'
rstRecordSet.Close
Else
MsgBox "No records were returned using the query " & cmdCommand.CommandText
End If
'
'Close the connection
'
conConnection.Close
'
'Release your variable references
'
Set conConnection = Nothing
Set cmdCommand = Nothing
Set rstRecordSet = Nothing
End Sub

Yo lo que estoy cambiando es la linea siguiente:

conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "" & "database.mdb;Mode=Read|Write"

Por:

conConnection.ConnectionString = "Driver={SQL Server};Server=www.dominio.eu;Database=nombredelabasededatos;Uid=usuario;Pwd=contraseña;"

Y me da un error en la siguiente línea:

conConnection.Open

Tambien he probado conlas conexiones de MyODBC 2.50 y MyODBC 3.51 que vienen en la web que me has mandado pero estoy haciendo algo mal por qeu no me funciona.

Me da el error '-2147467259(80004005)' en tiempo de ejecucción:

No se encuentra el nombre del origen de datos y no se especificó ningún controlador predeterminado.

Un saludo y muchas gracias por todo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar