Simple MySQL database connection with select statement
This snippet has coode to pull the rows from the db in a while loop.
post this code
'Import this to the very top of your code, make sure you have the mysql connector installed for VS
Dim conn As New MySqlConnection
Dim cmd As New MySqlCommand
Dim read As MySqlDataReader
'default root would have no pw...simply remove the password part if you have no pw
conn.ConnectionString = "server=127.0.0.1;user id=root; password=yourpw; database=mydb"
cmd.Connection = conn
cmd.CommandText = "SELECT id, name FROM mydb.table"
read = cmd.ExecuteReader
If read.HasRows Then
'name this variable anything you want
Dim id = read.GetInt32("id")
'for getting a string value:
Dim sName = read.GetString("name")
'make the pvname and pvid public(global) variables so you could use them outside while loop,
'this might not be needed in some cases
pvname = sName
pvid = id
Catch ex As Exception
If you want to be updated about similar snippets,
and follow our Channels