I have a SQL Server stored procedure that updates a table.
Here's my stored procedure
CREATE PROCEDURE [dbo].[usp_ExampleUpdate]
(@iID INT,
@sCodeName VARCHAR(MAX)
)
AS
BEGIN
UPDATE dbo.Example
SET CodeName = @sCodeName
WHERE ID = @iID
END
When I execute this stored procedure in SQL Server, it returns "1 row(s) affected", and the data is updated. But when I'm trying to execute this stored procedure from ASP.NET MVC using ExecuteNonQuery
, it returns 0.
Here's a sample of my code
public bool UpdateExample(SqlTransaction p_oTrans, int ID, string CodeName)
{
try
{
int iRowAffected = SqlHelper.ExecuteNonQuery(p_oTrans, "usp_ExampleUpdate", ID, CodeName);
return (iRowAffected > 0);
}
catch (Exception ex)
{
throw ex;
}
}
The iRowAffected
here always return 0, even though the stored procedure is successfully executed.
I've read the about this, but I still don't get it, why I always get 0.