简体   繁体   English

c#mysql存储过程插入返回值

[英]c# mysql Stored Procedure Insert return value

I have this MySQL Stored Procedure which I use to Insert a record into the database. 我有此MySQL存储过程,可用于将记录插入数据库。 If I use ExecuteScalar() or ExecuteNonQuery() command in C# to call this procedure, it is returning null for a successful insert. 如果我在C#中使用ExecuteScalar()ExecuteNonQuery()命令来调用此过程,则为成功插入而返回null。 As per my knowledge the number of rows affected is inserted, which is not 0 in my case. 据我所知插入受影响的行数,在我的情况下不是0。 Here's the link 这是链接

How do I return the number of inserted records 如何返回插入的记录数

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `Contact_AddNew`(codeName varchar(50), fName varchar(50), lName varchar(50), contact varchar(50))
BEGIN
    SET @codeName = codeName;
    SET @fName = fName;
    SET @lName = lName;
    SET @contact = contact;
    SET @query = 'INSERT INTO Contacts (contactName, firstname, lastname, phone) VALUES (?,?,?,?)';
    PREPARE stmt FROM @query;
    EXECUTE stmt USING @codeName, @fName, @lName, @contact;
    DEALLOCATE PREPARE stmt;
END

Answering my own question here.. 在这里回答我自己的问题..

A simple SELECT ROW_COUNT() will do.. 一个简单的SELECT ROW_COUNT()

http://dev.mysql.com/doc/refman/5.1/en/information-functions.html#function_row-count http://dev.mysql.com/doc/refman/5.1/zh-CN/information-functions.html#function_row-count

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM