Imports System Imports System.Data Imports MySql.Data.MySqlClient Public Class Form21 Dim conn As New MySqlConnection Private Function Connect(ByVal server As String, ByRef user As String, ByRef password As String, ByRef database As String) ' Connection string with MySQL Info conn.ConnectionString = "server=" + server + ";" _ & "user id=" + user + ";" _ & "password=" + password + ";" _ & "database=" + database + ";" Try conn.Open() Return True Catch ex As MySqlException Return MsgBox(ex.Message) End Try End Function Private Sub Form21_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Connect("erpredb.db.8756167.hostedresource.com", "erpredb", "Erp12345", "erpredb") Dim myAdapter As New MySqlDataAdapter Dim myCommand As New MySqlCommand() myCommand.Connection = conn myCommand.CommandText = "SELECT role FROM emproles" myAdapter.SelectCommand = myCommand Dim moddata As MySqlDataReader moddata = myCommand.ExecuteReader() moddata.Read() If moddata.HasRows Then Do While moddata.Read() ListBox2.Items.Add((moddata(0))) Loop Else End If moddata.Close() ' myCommand.Connection = conn ' myCommand.CommandText = "SELECT emplist FROM empnew" ' myAdapter.SelectCommand = myCommand ' moddata = myCommand.ExecuteReader() ' moddata.Read() ' If moddata.HasRows Then ' Do While moddata.Read() 'ListBox1.Items.Add((moddata(0))) ' Loop ' Else ' End If ' moddata.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim myCommand As New MySqlCommand Dim myAdapter As New MySqlDataAdapter Dim SQL As String myCommand.Connection = conn myAdapter.SelectCommand = myCommand SQL = "INSERT INTO empnew (emplist) VALUES ('" & TextBox1.Text & "')" myCommand.CommandText = SQL myCommand.ExecuteNonQuery() ListBox1.Items.Clear() myCommand.CommandText = "SELECT emplist FROM empnew" myAdapter.SelectCommand = myCommand Dim moddata As MySqlDataReader moddata = myCommand.ExecuteReader() moddata.Read() If moddata.HasRows Then Do While moddata.Read() ListBox1.Items.Add((moddata(0))) Loop Else End If moddata.Close() TextBox3.Text = "" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myCommand As New MySqlCommand Dim myAdapter As New MySqlDataAdapter Dim SQL As String myCommand.Connection = conn myAdapter.SelectCommand = myCommand SQL = "INSERT INTO emproles (role) VALUES ('" & TextBox3.Text & "')" myCommand.CommandText = SQL myCommand.ExecuteNonQuery() ListBox2.Items.Clear() myCommand.CommandText = "SELECT role FROM emproles" myAdapter.SelectCommand = myCommand Dim moddata As MySqlDataReader moddata = myCommand.ExecuteReader() moddata.Read() If moddata.HasRows Then Do While moddata.Read() ListBox2.Items.Add((moddata(0))) Loop Else End If moddata.Close() TextBox3.Text = "" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim myCommand As New MySqlCommand Dim myAdapter As New MySqlDataAdapter Dim SQL As String If ListBox2.SelectedItem = "Owners" Then Label7.Text = "The role 'Owners' is a primary role and cannot be deleted." timeout(2) Label7.Text = "status" Else myCommand.Connection = conn myAdapter.SelectCommand = myCommand SQL = "DELETE FROM emproles WHERE role = ('" & ListBox2.SelectedItem & "')" myCommand.CommandText = SQL myCommand.ExecuteNonQuery() ListBox2.Items.Clear() myCommand.CommandText = "SELECT role FROM emproles" myAdapter.SelectCommand = myCommand Dim moddata As MySqlDataReader moddata = myCommand.ExecuteReader() moddata.Read() If moddata.HasRows Then Do While moddata.Read() ListBox2.Items.Add((moddata(0))) Loop Else MsgBox("No rows returned.") End If moddata.Close() End If End Sub Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click End Sub End Class