priya
priya

Reputation: 1

Stored procedure passing parameter

If I execute a stored procedure with passing parameter it's executing fine. If I didn't pass a parameter, sometimes it is giving an error. null dataset.

Same sp if I pass with dummy parameter it is returning dataset.

Somebody help me please.

Priya

Upvotes: 0

Views: 277

Answers (1)

Fredrik Mörk
Fredrik Mörk

Reputation: 158289

If the stored procedure declares a parameter that is not optional, you will always need to pass a value to it. If you wish to pass a null value, you should assign DBNull.Value to the parameter before executing it from .NET code.

A parameter is optional if it is given a default value in the declaration, like this:

CREATE PROCEDURE [dbo].[spName]
(
    @ParamName varchar(50) = NULL
)
AS
BEGIN
  -- procedure code goes here
END

Upvotes: 3

Related Questions