Skip to content
Advertisement

Command.ExecuteScalar always return null while Stored Procedure in Management Studio runs fine

I have the following SQL stored procedure with one input parameter and one out parameter.

In the stored procedure above CanUserEdit column in tblUsers is bit type column and with default value to 0. Now when I execute this procedure in Management Studio it runs fine but when i use command.ExecuteScalar() in my C# code, it always returns null. Could anyone please tell me what I am doing wrong here.

Following is my C# method

Kind Regards

Advertisement

Answer

The problem is in the way you return data. If you want to use ExecuteScalar, you should not RETURN but instead simply SELECT.

Try to change the SP as following:

If you can’t change the SP, but the code, the solution is to read parameter ‘@ReturnValue’ with ExecuteNonQuery.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement