Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql query scope_identity error
    primarykey
    data
    text
    <p>hey guys im having a really tough time trying to solve this error please help im using c# with mysql connector and i wrote a query that goes something like this...</p> <pre><code>INSERT INTO employee VALUES(...); SELECT last_insert_id(); </code></pre> <p>but i keep getting this error for some reason :(</p> <pre><code>"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 'SELECT scope_identity()' at line 1". </code></pre> <p>The part i dont get about this error is that i dont have <code>scope_identity()</code> written anywhere in my code.</p> <p>I even removed the <code>SELECT last_insert_id();</code> part of my query but for some odd reason im still getting the same error.</p> <p>[EDIT] This generates the query perfectly but at the end it adds <code>scope_identity()</code> rather than <code>last_insert_id()</code></p> <pre><code>public static MySqlCommand insert(string tableName, params object[] values) { string sqlQuery = "INSERT INTO " + tableName + " VALUES("; for (int i = 0; i &lt; values.Count(); i++) { if (i == values.Count() - 1 &amp;&amp; values[i] is string) { sqlQuery = sqlQuery + "'" + values[i] + "'"; } else if (i == values.Count() - 1 &amp;&amp; values[i] is int) { sqlQuery = sqlQuery + values[i]; } else if (values[i] is string || values[i] is DateTime) { sqlQuery = sqlQuery + "'" + values[i] + "', "; } else if (values[i] is int) { sqlQuery = sqlQuery + values[i] + ", "; } } sqlQuery = sqlQuery + "); SELECT LAST_INSERT_ID(); "; MySqlCommand cmd = new MySqlCommand(sqlQuery); return cmd; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload