flynny
asked on
error in my SQL syntax
Hi Guys,
I am at a loss if i run the following statement in MySQLworkbench it works fine. However when I try using the ODBC connection in c# i get the following error;
ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.56-comm unity]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 @@IDENTITY' at line 1
the SQL i am using is very simple;
connection = new OdbcConnection(connectionS tring);
connection.Open();
String oQRY = String.Format("INSERT INTO `message` (fromID,subject,message,da te,importa nt) VALUES ({0},'{1}','{2}','{3}',{4} ); SELECT @@IDENTITY AS `identity`;", userID, SubjectTextBox.Text, MessageMemo.Text, timestamp, ImportantCheckBox.Value);
//Response.Write(oQry + "<BR>")
OdbcCommand com = new OdbcCommand(oQRY, connection);
com.ExecuteNonQuery();
com.CommandText = "SELECT Last_Insert_ID()";
int messageID = (int) com.ExecuteScalar();
the value of oQRY is
"INSERT INTO `message` (fromID,subject,message,da te,importa nt) VALUES (0,'test','test','2011-03- 16 00:00:00',True); SELECT @@IDENTITY AS `identity`;"
any ideas whats going on here please?
Thanks in advance,
Matt.
I am at a loss if i run the following statement in MySQLworkbench it works fine. However when I try using the ODBC connection in c# i get the following error;
ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.56-comm
the SQL i am using is very simple;
connection = new OdbcConnection(connectionS
connection.Open();
String oQRY = String.Format("INSERT INTO `message` (fromID,subject,message,da
//Response.Write(oQry + "<BR>")
OdbcCommand com = new OdbcCommand(oQRY, connection);
com.ExecuteNonQuery();
com.CommandText = "SELECT Last_Insert_ID()";
int messageID = (int) com.ExecuteScalar();
the value of oQRY is
"INSERT INTO `message` (fromID,subject,message,da
any ideas whats going on here please?
Thanks in advance,
Matt.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
String oQRY = String.Format("INSERT INTO `message` (fromID,subject,message,da
Hope this helps