Read Data from MySQL with VB.net

Talk2Tom11

Well-known member
Joined
Feb 22, 2004
Messages
144
Location
Westchester, NY
Hey i am using Visual Basic 2005 and a MySQL database.

I am able to connect to my database but i am alittle unsure about retrieving the information and displaying it in something like a txtbox.

What i want to do for example would be something like this...

SELECT Name FROM test WHERE Id = "1234";
and then have that name display in something like textbox1


this is my code so far...

[VB]Imports MySql.Data.MySqlClient

Public Class frmLogin
Dim conn As MySqlConnection


Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
conn = New MySqlConnection()
conn.ConnectionString = "Server=" & txtServer.Text & ";" _
& "Uid=" & txtUsername.Text & ";" _
& "Pwd=" & txtPassword.Text & ";" _
& "Database=test"

Try
conn.Open()
MessageBox.Show("Connection Opened Successfully")
conn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
End Sub[/VB]
 
Since you are using VS2005 - why dont you use the SQL controls in the toolbox. They do all the connections for you and it is a lot easier.
Use the SQL Connection (above the Access one).. it isnt just for SQL Server.
Hope that helps.
Amy

OH and it will test the query and connection right there in the wizard.. super easy... saves the hands for coding other things.. :)
 
Back
Top