Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all im getting an error when i run my insert query i have absoloutly no idea what this error is or how to handle it never seen it before please need help with this my code is

SQL
MySql.Data.MySqlClient.MySqlCommand audit_update = new MySql.Data.MySqlClient.MySqlCommand("INSERT INTO audit (member_id, date_time, table, field, old_value, new_value) VALUES (@member_id, @date_time, @table, @field, @old_value, @new_value,)", con5);
            audit_update.Parameters.AddWithValue("@old_value", first_name_hidden.Text);
            audit_update.Parameters.AddWithValue("@field", table.ToString());
            audit_update.Parameters.AddWithValue("@table", false.ToString());
            audit_update.Parameters.AddWithValue("@new_value", tbFirstName.Text);
            audit_update.Parameters.AddWithValue("@member_id", member_id.Text);
            audit_update.Parameters.AddWithValue("@date_time", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));


exception error im getting is this:

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 'table, field, old_value, new_value) VALUES ('53', '2012-10-18 12:27:14', 'False'' at line 1
Posted
Comments
Wes101 18-Oct-12 7:04am    
thanks for the help people after resetting my IIS and all that and then changing the keyword my query finally works thanks alot

SQL
INSERT INTO audit (member_id, date_time, table, field, old_value, new_value) VALUES (@member_id, @date_time, @table, @field, @old_value, @new_value,)";


In your above query there is extra ','. Remove that and then run your query. and also you are taking your Column name which are already used as a Keyword.

Thanks
 
Share this answer
 
v2
Take off the final comma:
SQL
"INSERT INTO audit (member_id, date_time, table, field, old_value, new_value) VALUES (@member_id, @date_time, @table, @field, @old_value, @new_value,)"
Becomes:
SQL
"INSERT INTO audit (member_id, date_time, table, field, old_value, new_value) VALUES (@member_id, @date_time, @table, @field, @old_value, @new_value)"
 
Share this answer
 
Comments
Wes101 18-Oct-12 6:45am    
still throwing me the same exception
OriginalGriff 18-Oct-12 6:50am    
Ah! "Table" is a keyword, which means you can't use it as a column name without escaping it:
"INSERT INTO audit (member_id, date_time, table, field, old_value, new_value)...
becomes
"INSERT INTO audit (member_id, date_time, [table], field, old_value, new_value)...

See here: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
how about this?
change this
"INSERT INTO audit (member_id, date_time, table, field, old_value, new_value) VALUES (@member_id, @date_time, @table, @field, @old_value, @new_value)"

to this
"INSERT INTO `audit` (`member_id`, `date_time`, `table`, `field`, `old_value`, `new_value`) VALUES (@member_id, @date_time, @table, @field, @old_value, @new_value)"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900