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:
The way it should work is the user enters some information into TextBox1Code: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()
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:
Any help on this is much appreciated.MySQL Syntax Error (On Line 1) WHERE AnotherColumnName = SomeNumbers
Thanks




Reply With Quote
