当我尝试删除数据库中的一行时,已使用错误返回

时间:2018-09-07 05:45:50

标签: c# mysql sql

我想用c#删除数据库中的一行。但返回的是:

  

无法更新存储函数/触发器中的表“ medikal”,因为调用该存储函数/触发器的语句已使用该表。

C#代码:

 using (MySqlConnection connect = new MySqlConnection(connectionString))
     {
        using (MySqlCommand cmd = new MySqlCommand(db_name + ".delete_medikalislem", connect))
            {
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("p_id", medikal_id);
               connect.Open();
               cmd.ExecuteNonQuery();
               connect.Close();
            }
      }

存储过程代码:

DELETE FROM medikal WHERE islem_id = p_id;

删除触发代码后:

BEGIN

DECLARE tl_ integer default 0;
DECLARE usd_ integer default 0;
DECLARE eur_ integer default 0;
DECLARE gbp_ integer default 0;
DECLARE toplam_ integer default 0;

SELECT tl, usd, eur, gbp INTO tl_, usd_, eur_, gbp_ FROM medikalfirmalar WHERE isim = OLD.medikal_isim;
DELETE FROM medikal_caritahsilat WHERE islem_id = OLD.islem_id;
    IF (OLD.birim='TL') THEN
    SET toplam_= tl_ - OLD.tutar;
    UPDATE medikalfirmalar SET tl = toplam_ WHERE isim = OLD.medikal_isim;
    END IF;
    IF (OLD.birim='USD') THEN
    SET toplam_= usd_ - OLD.tutar;
    UPDATE medikalfirmalar SET usd = toplam_ WHERE isim = OLD.medikal_isim;
    END IF;
    IF (OLD.birim='EUR') THEN
    SET toplam_= eur_ - OLD.tutar;
    UPDATE medikalfirmalar SET eur = toplam_ WHERE isim = OLD.medikal_isim;
    END IF;
    IF (OLD.birim='GBP') THEN
    SET toplam_= gbp_ - OLD.tutar;
    UPDATE medikalfirmalar SET gbp = toplam_ WHERE isim = OLD.medikal_isim;
    END IF;
END

我该如何解决?

0 个答案:

没有答案