My C# code calls a stored procedure with a return value (not a return parameter).
// C#
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.StoredProcedure;
int retval = cmd.ExecuteNonQuery();
con.Close();
return retval;
The stored procedure inserts a record and grabs the new record id with scope_identity().
/* SQL */
SET NOCOUNT ON;
INSERT INTO [dbo].[table] (columns)
VALUES (@parameters);
SET @iParentRowId = Scope_identity();
INSERT INTO [table_related] (ParentRowId, Column2) VALUES (@iParentRowId, @Column2Value);
RETURN @iParentRowId;
The sp works exactly as expected, but C# returns -1. (I assume that is a success indicator.)
If I SET NOCOUNT OFF, I get the number of rows affected, which I don't care about.
Can I use RETURN from the sp to get the new RowId?