You are not logged in.

#1 20 Feb 2008 10:00 pm

winsr
Extreme Member
Registered: Mar 2007
Posts: 90

MySQL or MS SQL 2005 question...

Do you guys know how can i make to do a windows local VB application to connect to an online MySQL or SQL database? Online as in public database or so.??? i mean, i have apps to connect to local access or sql files, or even sql servers, but never userd MySql, nor any kind of online database, any clues?

Offline

 

#2 21 Feb 2008 1:24 am

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: MySQL or MS SQL 2005 question...

yep.  a long time ago a guy wrote a .net ADO.NET provider for mysql.  a little while later, mysql aquired him and his code and now its part of mysql's official releases.  I used it for a company I was working for back before mysql bought it.

it works just like every other ado.net provider that ships w/ .net.  it comes with documentation and samples (though I think they're all in C# not VB.NET), or you could google ado.net and find plenty of examples.  the only difference would be that the objects are prefixed Mysql instead of Odbc or OleDb or Sql (MySqlConnection, MySqlCommand, MySqlDataReader and so on).

you'll have to read up on the documentation on the connection string, but code to pull records from a database would look something like this:

Code:

' the string passed in to your connection specifies the server connection info. Check their docs on what ConnectionString parameters you'll need to pass in
Dim con As MySqlConnection = New MySqlConnection("Server=127.0.0.1;User Name=root;")
con.Open
Dim command As MySqlCommand = con.CreateCommand
command.CommandText = "SELECT * FROM `users` WHERE `name` = 'foo`"
Dim reader As MySqlDataReader = command.ExecuteReader
Do While reader.Read
    ' reader.Item is like an associative array that lets you access items by the field names returned in your query
    Dim name As String = CStr(reader.Item("name"))
    Dim email As String = CStr(reader.Item("email"))
Loop
con.Close
con.Dispose

inserting is pretty much the same, off of your command object you have an executenonquery (for query's that don't return anything), executescalar (which return a single field value).  if you are working with DataSet's you can create a DataAdapter from  your command object (pass the command into its constructor) and you can use that to fill some data set, and pass that into a data grid that will display the data in a pre-formatted grid.

you can download their provider here: http://dev.mysql.com/downloads/connector/net/5.0.html

to use it, download / install, copy the dll into your project, add a reference to that dll in your project, add the necessary using statements, and roll.

Offline

 

#3 21 Feb 2008 8:40 am

winsr
Extreme Member
Registered: Mar 2007
Posts: 90

Re: MySQL or MS SQL 2005 question...

sound really simple... way to simple to be true.

Ill give it a test in these day, and come back with any black holes i might find in the way, but thanks for the info... wink

Offline

 

#4 21 Feb 2008 12:25 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: MySQL or MS SQL 2005 question...

yea microsoft did a great job at the whole ado.net stuff. 

yea ask away, its about as easy as falling over, so I'm sure you'll figure it out quickly, but if there is anything questionable, ask away.

Offline

 



© 2003 - 2024 NullFX
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License