I want to provide a web service for users to insert or update some values in a table. The user enters an ID and three parameters. If the ID does not exist in the database I want to return 0, fail or similiar. When I test the code below and provide an ID that doesn't exist the stored procedure return 1 cell (Return Value) with 0 but the status gets set to 1. I guess it is because I use ToString() when I execute the query and it returns 1 cell. So how should I improve the code below?
I have this code in a method:
string status = "";
SqlParameter[] param = {
new SqlParameter("@ID", ID),
new SqlParameter("@Flag", Flag),
new SqlParameter("@C_Interval", C_Interval),
new SqlParameter("@D_Interval", D_Interval)
};
status = DatabaseHelper.ExecuteNonQuery("sp_InsertInstruction", param);
return status;
In ExecuteNonQuery I pass on the stored procedure command to the database
// skipped some of the code this example
status = cmd.ExecuteNonQuery().ToString();
return status;
My stored procedure looks like:
ALTER PROCEDURE dbo.sp_InsertInstruction
@Flag char(1) = null,
@C_Interval int=null,
@D_Interval int=null,
@ID char(20),
AS
DECLARE @Entity_ID int
SET @Entity_ID = (SELECT ID FROM Entity WHERE ID = @ID)
INSERT INTO Instructions(Flag, C_Interval, D_Interval, Entity_ID)
VALUES (@Flag, @C_Interval, @D_Interval, @Entity_ID)
Thanks in advance.