MySQL分隔符语法错误仅在C#上获得错误

时间:2018-11-05 20:28:38

标签: c# mysql phpmyadmin

我有创建过程代码。当我尝试在phpmyadmin中运行创建过程代码时,它是可行的。但是当我尝试在C#中运行时,它会返回如下错误:

  

您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以获取在'DELIMITER !!附近使用正确的语法!

创建过程代码:

DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `update_alldoctorname`(IN `p_doktor` VARCHAR(65) CHARSET latin5, IN `p_eski` VARCHAR(65) CHARSET latin5)
    NO SQL
    BEGIN
UPDATE users SET hekim=p_doktor WHERE hekim=p_eski;
UPDATE tedavi SET tedavi_doktor=p_doktor WHERE tedavi_doktor=p_eski;
UPDATE medikal SET doktor=p_doktor WHERE doktor=p_eski;
UPDATE cek_devreden SET unvan=p_doktor WHERE unvan=p_eski;
END
;;
DELIMITER ;

我该如何解决?

1 个答案:

答案 0 :(得分:0)

在C#中,不能将DELIMITER ;;语法与MySqlCommand一起使用。相反,只需将CREATE PROCEDURE语句的主体用作MySqlCommand.CommandText并执行它即可:

using (var command = yourConnection.CreateCommand())
{
    command.CommandText = @"CREATE DEFINER=`root`@`localhost` PROCEDURE `update_alldoctorname`(IN `p_doktor` VARCHAR(65) CHARSET latin5, IN `p_eski` VARCHAR(65) CHARSET latin5)
    NO SQL
    BEGIN
        UPDATE users SET hekim=p_doktor WHERE hekim=p_eski;
        UPDATE tedavi SET tedavi_doktor=p_doktor WHERE tedavi_doktor=p_eski;
        UPDATE medikal SET doktor=p_doktor WHERE doktor=p_eski;
        UPDATE cek_devreden SET unvan=p_doktor WHERE unvan=p_eski;
    END";
    command.ExecuteNonQuery();
}