Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to access a MySQL database from

Status
Not open for further replies.

geetapm

Programmer
Feb 12, 2002
17
IN
How to access a MySQL database from VB , Urgent
Thanks

Bye
 
Thanks for ur reply.

i got connection thru ODBC.
now i want to try it thru ADODB.
problem is what DataSource I have to give,
since MYSQL doesn't show me any DataSource.
If someone can through light on this matter,
it will be a big favour.

Bye
 
This should open you an ADODB Connection to a SQL server.
The only other thing you need to do is projects|references in VB and ensure that ADO is selected.

Code:
Dim dbDMS As ADODB.Connection

Set dbDMS = New ADODB.Connection
dbDMS.Open "Provider=sqloledb; Data Source=
ServerName
Code:
;Initial Catalog=
IntialDatabase
Code:
;User Id=
UserName
Code:
;Password=
PassWord
Code:
;"

The database is now open. You then will probably want some recordsets to work on....

Code:
Dim rstTest As ADODB.Recordset
Dim strSelectSQL as String

strSelectSQL = "Select * from TestTable"

Set rstTest = New ADODB.Recordset
rstTest.ActiveConnection = dbDMS
rstTest.Open strSelectSQL
Do Processing
Code:
rstTest.close

Or you can execute stored procedures

Code:
dbDMS.Execute ("Insert testtable(Name, Surname) values (Robert, Mottram)")


When all is done on the database

dbDMS.close

Once the record set is created most of the function seam to work the same with ADODB as they did through ODBC (or at least the ones I have tried!)

I hope that this may help you

Robert Mottram
 
I think the idea here is to use ADO to connect to the ODBC source.... I'm going to be messing with this as well soon...

 
Sorry, I just noticed in my last post I was connecting to MSSQL not MySQL doh! [blush]

Will gives a large number of ADO connection string examples. If you have created the ODBC connection to MySQL ( which I could not workout how to do last time I looked) you this page has an example of a connection string to ODBC. You would use this

Code:
oConn.Open "DSN=mySystemDSN;Uid=myUsername;Pwd=myPassword;"

I hope this makes some more sence!

Robert
 
thanx to all of u guys.

It was a great help to me.

Thanx once again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top