MySQL的。插入存储过程受影响的行的计数始终为0

时间:2014-07-12 11:28:32

标签: c# mysql stored-procedures

我从c#代码中调用存储过程,将一行插入表中。我的问题是我总是得到0个受影响的行。这是代码

存储过程代码

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `AddInfo`(
                    IN _activationDate datetime, 
                    IN _organization varchar(100),
                    IN _email varchar(45),  
                    IN _tableName varchar(35))
BEGIN
set @sqlquery = concat('insert into ', _tableName, ' values (?, ?, ?)');
prepare stmt from @sqlquery;
set @activationDate = _activationDate;
set @orgaization = _organization;
set @email = _email;

execute stmt using @activationDate, @orgaization, @email,;
deallocate prepare stmt;
END

C#代码

using (MySqlConnection conn = new MySqlConnection(connStr))
        {
            string spName = "AddInfo";
            MySqlCommand cmd = new MySqlCommand(spName, conn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@_activationDate", activationDate);

            cmd.Parameters.AddWithValue("@_organization", organization);
            cmd.Parameters.AddWithValue("@_email", email);

            cmd.Parameters.AddWithValue("@_tableName", tableName);

            conn.Open();

            int rowsAffected = cmd.ExecuteNonQuery();
            bool added = rowsAffected == 1 ? true : false;
            conn.Close();

            return added;
        }

当我运行此代码时,行已成功添加到表中,但rowsAffected始终为0.我的问题在哪里?谢谢

0 个答案:

没有答案