Question MySql query would not execute

gate7cy

Well-known member
Joined
May 11, 2009
Messages
119
Programming Experience
3-5
Hello everybody once again. Recently as I was finishing some basic insert queries I came upon a puzzle which till now I dont know what I am doing wrong. I have a very basic insert query which just would not execute throwing an error saying that there is a syntax error in my query. I have checked over and over again going back and forward from my database columns to the actual code. I cannot find what I am doing wrong. Here is the query:

VB.NET:
  Dim query4 As String
                        query4 = " insert into sizes (barcode, name, code, 40, totalquan) values (" & barcode1 & ", '" & NameTextBox.Text & "', '" & ClothecodeTextBox.Text & "', " & S40TextBox.Text & ", " & totalTextBox.Text & ")"
                        Dim cmd4 As MySqlCommand = New MySqlCommand(query4, conn)
                        cmd4.ExecuteNonQuery()
                        conn.Close()


Please some help will be greatly appreciated. Thanks for your time and effort.
cheers
 
1. If you used parameters, it would make reading your SQL a lot easier :)

2. Do you really have a column named "40"?

3. I dont use MySQL, but is "name" a reserved word?

4. Is barcode a string or numeric? If it's a string, your SQL is wrong. If it's numeric, you should be using Option Strict On and writing barcode1.ToString

I expect one (or more) of those might help :)
 
thanks for the reply. The issue was with the column '40' . I changed to 's40' and it works. Thank you for the tip.
 
Back
Top