Visual Basic Help

Pop your questions regarding Home automation software here.....
Post Reply
s8utt
Starting Member
Starting Member
Posts: 33
Joined: Wed Jan 24, 2007 6:46 pm
Location: United Kingdom

Visual Basic Help

Post 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
Lempens
Member
Member
Posts: 265
Joined: Wed Dec 12, 2007 1:24 am
Location: Netherlands

Re: Visual Basic Help

Post 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
s8utt
Starting Member
Starting Member
Posts: 33
Joined: Wed Jan 24, 2007 6:46 pm
Location: United Kingdom

Re: Visual Basic Help

Post 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
Lempens
Member
Member
Posts: 265
Joined: Wed Dec 12, 2007 1:24 am
Location: Netherlands

Re: Visual Basic Help

Post 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.
s8utt
Starting Member
Starting Member
Posts: 33
Joined: Wed Jan 24, 2007 6:46 pm
Location: United Kingdom

Re: Visual Basic Help

Post 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 :)
s8utt
Starting Member
Starting Member
Posts: 33
Joined: Wed Jan 24, 2007 6:46 pm
Location: United Kingdom

Re: Visual Basic Help

Post 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 :)
Post Reply

Return to “Questions & Discussions Forum”