Error inserting records into MySql table using Asp 2.0 [modified]
-
I created a form view in asp.net for a data entry web page. User inputs data which is supposed to get inserted into my MySql database in a existing database. but when I try the following code, I get the following error: System.Data.Odbc.OdbcException: ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.45-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'product_id, 'Button Up'product_name, 'shirts'product_desc, 1000tot_qty, 36tot_ca' at line 2 This is the script I am running in my .aspx file. InsertCommand="insert into product(product_id, product_name, product_desc, tot_qty, tot_cartons, cost, tot_colors,qty_per_carton, arrival_date, custom_clearedby, ship_mode) values( ?product_id, ?product_name, ?product_desc, ?tot_qty, ?tot_cartons, ?cost, ?tot_colors,?qty_per_carton, ?arrival_date, ?custom_clearedby, ?ship_mode); I would really appreciate any help/insight. Thanks in advance
modified on Monday, May 19, 2008 12:17 PM
-
I created a form view in asp.net for a data entry web page. User inputs data which is supposed to get inserted into my MySql database in a existing database. but when I try the following code, I get the following error: System.Data.Odbc.OdbcException: ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.45-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'product_id, 'Button Up'product_name, 'shirts'product_desc, 1000tot_qty, 36tot_ca' at line 2 This is the script I am running in my .aspx file. InsertCommand="insert into product(product_id, product_name, product_desc, tot_qty, tot_cartons, cost, tot_colors,qty_per_carton, arrival_date, custom_clearedby, ship_mode) values( ?product_id, ?product_name, ?product_desc, ?tot_qty, ?tot_cartons, ?cost, ?tot_colors,?qty_per_carton, ?arrival_date, ?custom_clearedby, ?ship_mode); I would really appreciate any help/insight. Thanks in advance
modified on Monday, May 19, 2008 12:17 PM
When trouble shooting commands like this, it always helps to show all of the relevant code (e.g. paramaters). Each paramater "?some_param" should be assigned a value, you did not post this part of the code. Also, the paramaters should be added in the same order they are used in you MySql statement. I also don't see you closing the string, however this might be a copy/paste typo. Nonetheless, complete code is essential especially when this appears to be some type of string problem. Based on your posted example, they should look like this: mysqlCmd.Parameters.AddWithValue("?product_id", "some_value") mysqlCmd.Parameters.AddWithValue("?product_name", "some_value") mysqlCmd.Parameters.AddWithValue("?product_desc", "some_value") etc.. Hope this helps!