Here is a good tutorial about using MySQL and VB together:
The piece from this that may be of interest to you:
Sub Main()
Dim cs As String = "Database=testdb;Data Source=localhost;" _
& "User Id=testuser;Password=test623"
Dim conn As New MySqlConnection(cs)
Try
conn.Open()
Dim stm As String = "SELECT * FROM Authors"
Dim cmd As MySqlCommand = New MySqlCommand(stm, conn)
Dim reader As MySqlDataReader = cmd.ExecuteReader()
While reader.Read()
Console.WriteLine(reader.GetInt32(0) & ": " _
& reader.GetString(1))
End While
reader.Close()
Catch ex As MySqlException
Console.WriteLine("Error: " & ex.ToString())
Finally
conn.Close()
End Try
End Sub
Note the MySqlDataReader
(reader
) object. This lets you get various types of data back. You need to know the column type you are reading, and use the appropriate method.
For example if you're reading a boolean, you would write:
reader.GetBoolean(0)
Or a DateTime:
reader.GetDateTime(0)
This example uses int arguments to represent the column number, but I find this less intuitive than using the column name. Fortunately MySqlDataReader
supports column names as well:
reader.GetString("account_type")
The example doesn't show reading these values into variables, but it's fairly trivial:
Dim accountType As String
...
accountType = reader.GetString("account_type")
(This assumes that your account type column is a string.)
Hopefully this helps get you on the right track.