Sk Asraf Sk Asraf - 1 month ago 4x
MySQL Question

mysql, error when insert value

i cant find out where my error please help me any one.

when i am run my page then i am getting an exception like thet

:MySql.Data.MySqlClient.MySqlException (0x80004005): 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 'usage,details,comment)values( 4, 'Laptop', 'g.purpose', 'gfhg', '')' at line 1 at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) at

i am trying to find out error but i cant

my code is

MySqlConnection con = new MySqlConnection();
con.ConnectionString = WebConfigurationManager.ConnectionStrings["mysql_con"].ConnectionString;

string query2 = "INSERT INTO m_prod_type(com_id,name,usage,details,comment)" +
"values( @com_id, @name, @usage, @details, @comment)";
MySqlCommand cmd = new MySqlCommand(query2, con);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@usage", uses);
cmd.Parameters.AddWithValue("@details", details);
cmd.Parameters.AddWithValue("@comment", comment);
// cmd.Transaction = tran;
// tran.Commit();
// isSucess = true;


plese help me.


In MySQL, usage is a reserved word (see the list here).

So, you need to escape it:

INSERT INTO m_prod_type(com_id, name, `usage`, details, comment)" +
            "values( @com_id, @name, @usage, @details, @comment)

I would also advise you to specify the type explicitly, rather than using AddWithValue(). That function can cause problems.