Page 1 of 1

Visual Basic Help

Posted: Thu Mar 11, 2010 4:15 pm
by s8utt
Hello, I'm trying to add some code to an existing program.

I am using Visual studio 2008 and I need to write some code to write some data to a mysql database.

I can get this working in excel and have been doing this for some time, I cannot however get it working in Visual Studio.

The code I'm using is ...

Code: Select all

Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset

      conn.Open "UID=root;PWD=password;DATABASE=db;SERVER=localhost;DRIVER=MYSQL ODBC 5.1 DRIVER"

      Set cmd.ActiveConnection = conn

      rs.CursorLocation = adUseClient

      cmd.CommandText = "INSERT INTO blah (blah2) VALUES (blah3)"
      cmd.Execute
I have the mysql 5.1 odbc driver installed and as I said running this code through excel runs without any problems, however using this code in VS does not.
What am I doing wrong / missing ?


Thanks

Re: Visual Basic Help

Posted: Thu Mar 11, 2010 4:26 pm
by Lempens
Do you have the MySQL database driver for VB.net installed?

You can use the wizard to make a dataset. If this works, then your code must work to.
There is also a very good sample on the site of MySql

Re: Visual Basic Help

Posted: Thu Mar 11, 2010 4:44 pm
by s8utt
I have the mysql odbc 5.1 installed.

As I said I use this code in excel and everything works.

If there are further steps I need to do to get it working in visual studio can you educate me as to what these steps are

thanks

Re: Visual Basic Help

Posted: Thu Mar 11, 2010 4:50 pm
by Lempens
I'm at work now but tonight I will send you code sample. But I use the ADO.NET Driver for MySQL (Connector/NET). Not the ODBC.

When you download the driver there are some samples on how te read and write data to the database.

Re: Visual Basic Help

Posted: Thu Mar 11, 2010 5:23 pm
by s8utt
I don't have any problems using the connector/net. I've got that installed as well I think.

The thing I wasn't sure about was do you need to add references etc as well as installing the driver and using the code.

thanks for your help :)

Re: Visual Basic Help

Posted: Thu Mar 11, 2010 11:56 pm
by s8utt
lo m8, just to let you know I think I've sussed it.

got insert, update and read working

used the mysql connector/net

thanks for the pointer :)