Results 1 to 12 of 12

Thread: Writing to MySQL problem

Threaded View

  1. #1

    Thread Starter
    New Member GrantK's Avatar
    Join Date
    Mar 2015
    Location
    Stratford New Zealand
    Posts
    12

    Question Writing to MySQL problem

    Hi I don't post often although I am here a lot learning from other posts.

    Details:
    VB.NET 2010
    MySQL v5.5.42-cll

    With the current setup I can fetch MYSQL data from the remote server to display in forms.
    Using same rules I am trying to submit data back to database and fail with MYSQL Syntax Error.

    Here's the code:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim READER As MySqlDataReader
            Dim cmd As New MySqlCommand
            Dim con As New MySqlConnection
            Dim DatabaseName As String = "server-recognized-db-name"
            Dim server As String = "ip-number"
            Dim userName As String = "db-user"
            Dim password As String = "db-pass"
            If Not con Is Nothing Then con.Close()
            con.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password, DatabaseName)
    
            Try
                con.Open()
                Dim Query As String
                Query = "insert into DatabaseName.TabelName (ColumnName) values ('" & TextBox1.Text & "') WHERE (AnotherColumnName) = ('" & TextBox2.Text & "')"
                cmd = New MySqlCommand(Query, con)
                READER = cmd.ExecuteReader
    
                MessageBox.Show("Data Saved")
                con.Close()
    
            Catch ex As MySqlException
                MessageBox.Show(ex.Message)
            Finally
                con.Dispose()
    
            End Try
    
            con.Close()
    The way it should work is the user enters some information into TextBox1
    Then enters their account ID into TextBox2
    The value of TextBox2 determines where the data of TextBox1 should be saved in the database.

    Example:

    Table Name
    Table Column 1 - Account ID (TextBox2 user entered value)
    Table Column 2 - Some other content
    Table Column 3 - Where I want to save the content of TextBox1

    The MYSQL error I keep getting regardless of how many different ways I write this is:

    MySQL Syntax Error (On Line 1) WHERE AnotherColumnName = SomeNumbers
    Any help on this is much appreciated.
    Thanks
    Last edited by GrantK; Apr 28th, 2015 at 01:02 AM. Reason: added MySQL version
    Spooning it with style


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width