时间:2021-07-01 10:21:17 帮助过:2人阅读
存储过程设计如下:
CREATE PROCEDURE `pro_SaveData`(IN `sinst` varchar(500),IN `supdt` varchar(500)) BEGIN #直接更新记录 set @v_updsql=supdt; prepare stmt from @v_updsql; EXECUTE stmt; #记录不存在,执行INSERT IF ROW_COUNT() =0 THEN set @v_intsql=sinst; prepare stmt from @v_intsql; EXECUTE stmt; END IF; deallocate prepare stmt; END;
C#调用如下:
int r = data.ExecuteNonQuery(System.Data.CommandType.StoredProcedure, @"CALL pro_SaveData (' INSERT INTO `table` VALUES ('1', 'username')', 'UPDATE table SET name='table222' WHERE id='1';')", null);