Error When updating a record in a MySQL Database

bemis82

Member
Joined
Jun 4, 2011
Messages
14
Programming Experience
Beginner
Hey everyone, i have a relatively simple problem on my hands and can seem to figure it out so i'm posting here to see if there's any obvious mistakes i'm overlooking. All i'm tring to do is connect to my MysQL database on my Local host and update a record in my "customers" Table. The Error i've been getting is under Public Sub DeactivateAccount(), the MyCommand.ExecuteNonQuery() line of the code. The error is saying there is "no database selected". Below is the code i have.

thanks for the help.

[XCODE]
Imports MySql.Data.MySqlClient

Public Class FinalFailedPinNumberAttempt

Dim connectionstring As String = "Server=localhost;user id=root;Password=;database=mydatabase"
Dim SQLConnection As MySqlConnection = New MySqlConnection

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

SuspendLayout()
Dim Fade As Double
For Fade = 0.0 To 1.1 Step 0.2
Me.Opacity = Fade
Me.Refresh()
Threading.Thread.Sleep(100)
Next
Call DeactivateAccount()
End Sub

Public Sub DeactivateAccount()

Try
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try

Dim sqlquery As String = "UPDATE customers SET Account_Deactivated = 'Yes' WHERE Customer_Card_ID = '" & SwipeID.swipetxt.Text & "'"

Dim mycommand As New MySqlCommand(sqlquery, SQLConnection)
Dim myadapter As New MySqlDataAdapter()
Dim Table As New DataTable
mycommand.Connection = SQLConnection
mycommand.CommandText = sqlquery
mycommand.CommandType = CommandType.Text
mycommand.ExecuteNonQuery()
SQLConnection.Close()
End Sub
End Class
[/XCODE]
 
Back
Top