【问题标题】:MySQL ODBC driver: SQL works in an editor like workbench but not within .NET odbcMySQL ODBC 驱动程序:SQL 在工作台等编辑器中工作,但在 .NET odbc 中不工作
【发布时间】:2014-06-14 01:05:56
【问题描述】:

ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.5.9-log]您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以获取正确的语法,以便在 '​CALL spCreateTrade (27756,'27751','820','1','126','TRADE','Approved')' 附近使用第 1 行

此查询在 MySQL 工作台等编辑器中运行良好。我使用了相同的 SQL 用户。我一生都无法弄清楚为什么这不起作用。

        parameters.Add(new OdbcParameter("pEmployeeDB_ID", co.DB_ID));
        parameters.Add(new OdbcParameter("pOther_EmployeeDB_ID", EmployeeDB_ID.ToString()));
        parameters.Add(new OdbcParameter("pCO_ID", CO_ID.ToString()));
        parameters.Add(new OdbcParameter("pDPID", co.Department_Position_ID.ToString()));            
        parameters.Add(new OdbcParameter("pCompleted_By", Completed_By.ToString()));
        parameters.Add(new OdbcParameter("pAction_type", "TRADE"));
        parameters.Add(new OdbcParameter("sStatus", "Approved"));

        string sql = "​CALL spCreateTrade (?,?,?,?,?,?,?)";


        DataSet retVal = new DataSet();


        if (connString != null)
        {
            using (OdbcConnection connection = new OdbcConnection(connString))
            {
                //Open it
                connection.Open();
                //Create the command
                OdbcCommand command = new OdbcCommand(sql, connection);
                command.CommandType = cmdType;
                if (parameters != null)
                {
                    foreach (OdbcParameter p in parameters)
                    {
                        command.Parameters.Add(p);
                    }
                }

                command.ExecuteNonQuery();


                //Close the connection.
                connection.Close();
            }
        }

【问题讨论】:

    标签: c# mysql asp.net .net odbc


    【解决方案1】:

    将 SQL 括在括号中:

    string sql = "{ ​CALL spCreateTrade (?,?,?,?,?,?,?) }";
    

    【讨论】:

      猜你喜欢
      • 2011-06-17
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      相关资源
      最近更新 更多