Accessing MySQL from application

beno

New member
Joined
Aug 17, 2004
Messages
3
Programming Experience
Beginner
Hey how's it going,
I'm basically yet another newb who hasn't used VB in a long time and I'm trying to get back into it for some projects I wanted to complete at home. I'm currently using VS.NET 2003 for the first time and I'm trying to learn how to connect to a mysql database I have setup. I'm pretty sure all the required files are installed to connect to a data source, I'm just not sure exactly how to connect and retrieve data. Here is what I have so far, note that when I try running this code I receive this error "An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in system.data.dll" .. I'm kinda stuck, thanks for all your help:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim connectionString As String = "Driver={MySQL};SERVER=localhost;DATABASE=bmp;"

Dim conn As New Odbc.OdbcConnection(connectionString)

conn.Open()

Dim da As New Odbc.OdbcDataAdapter("SELECT id, movie, filename, description, views FROM movie", conn)

Dim ds As New DataSet("bmp")

da.Fill(ds, "movies")

dataGrid1.DataSource = ds.DefaultViewManager

conn.Close()

End Sub
 
Got the data!

it looks nasty in the datagrid.. but it works. i changed a few lines as you'll see below.. let me know if there's anything else I should need to know or if anyone has any good links that would be great too :D

Dim connectionString As String = "Driver={MySQL};SERVER=localhost;DATABASE=bmp;UID=root;PID="

Dim conn As New Odbc.OdbcConnection("DSN=BMP")

conn.Open()

Dim da As New Odbc.OdbcDataAdapter("SELECT id, movie, filename, description, views FROM movies", conn)

Dim ds As New DataSet("bmp")

da.Fill(ds, "movies")

DataGrid1.DataSource = ds.DefaultViewManager

conn.Close()

 
Back
Top