First you have to go to mysql.com and download the .NET Connector. Then add that into your application as a reference. Call it in the top of the code:
Imports MySql.Data.MySqlClient
As you can see the coding is very similar already. Then after that is where it gets hard. I personally create a class variable called myConnString which has the connection string set to it so I don't have to keep re-writing it over and over.
Dim myConnString = "server=YOURHOST;user id=YOURUSERNAME;password=YOURPASSWORD; database=YOURDB"
That wasn't too bad. Again the point of this is to just show you how to do stuff, it's up to you to take what I show you and turn it into your own. The next part is about inserting information into tables.
Dim command As New MySqlCommand Dim conn As New MySqlConnection(myConnString) 'your connection string command.CommandText = "INSERT INTO sometable(id, money, picture) VALUES('Someid','someval','someobject')" Try conn.Open() command.ExecuteNonQuery() 'Executes a query the requires no output Catch error As MySqlException MessageBox.Show("MySQL Error: " & error) End Try
Again, simple. Now for selecting information from the database and putting it into variables which I found to be the hardest part but with a lot of trial and error found it out.
Dim command As New MySqlCommand Dim read As New MySqlDataReader() Dim conn As New MySqlConnection(myConnString) 'your connection string conn.Open() command.CommandText = "SELECT * FROM sometable WHERE username='" & txtUser.Text & "' AND password='" & txtPass.Text & "'" read = command.ExecuteReader() While read.Read() Dim id = read("id").ToString() Dim email = read("email").ToString() End While
Now with that code above you would be able to display the id and e-mail address of the user with that username and password combo anywhere you wanted. You can now put that code anywhere on your form: textboxes, listboxes, etc.
Well, I hope that helped everyone out with any confusion about using MySQL and their .NET applications. Also, I'm on a work computer right now so I don't have visual basic or anything on here to test out the code. If it doesn't work, let me know and I'll fix it when I get home. Everything should work though.
Edited by JoeyMagz, 26 July 2008 - 11:45 PM.