4 Replies - 1288 Views - Last Post: 17 June 2011 - 07:44 AM Rate Topic: -----

#1 bemis82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 03-June 11

Getting Error when Updating records in MySQL database

Posted 17 June 2011 - 05:45 AM

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.

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



Is This A Good Question/Topic? 0
  • +

Replies To: Getting Error when Updating records in MySQL database

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9487
  • View blog
  • Posts: 35,785
  • Joined: 12-June 08

Re: Getting Error when Updating records in MySQL database

Posted 17 June 2011 - 07:14 AM

Try throwing the db name before the table name.

update <db name>.<table name> set ...

Was This Post Helpful? 0
  • +
  • -

#3 bemis82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 03-June 11

Re: Getting Error when Updating records in MySQL database

Posted 17 June 2011 - 07:22 AM

View Postmodi123_1, on 17 June 2011 - 07:14 AM, said:

Try throwing the db name before the table name.

update <db name>.<table name> set ...



Ok, i just tried that and this is the new error message i'm getting...

UPDATE command denied to user ''@'localhost' for table 'customers'
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,606
  • Joined: 23-August 08

Re: Getting Error when Updating records in MySQL database

Posted 17 June 2011 - 07:27 AM

Where do you ever set the connection string in the SQLConnection object?
Was This Post Helpful? 1
  • +
  • -

#5 bemis82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 03-June 11

Re: Getting Error when Updating records in MySQL database

Posted 17 June 2011 - 07:44 AM

View PostJackOfAllTrades, on 17 June 2011 - 07:27 AM, said:

Where do you ever set the connection string in the SQLConnection object?



That fixed it. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1