What is the true sequence to make this code run as I tried many time but I don\'t get a valid result
// the code of SQL stored procedure
set ANSI_NULLS
You're executing .ExecuteScalar() so you're expecting back a result set with a single row, single column from the stored procedure - but you're not selecting anything at the end of your stored proc!
You need to change your last line in the stored proc from
return @result
to
SELECT @result
and then it should work.