存储过程设计如下:
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);
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com