简体   繁体   English

存储过程传递参数

[英]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. 如果我通过哑参数传递相同的sp,它将返回数据集。

Somebody help me please. 请有人帮我。

Priya 普里亚

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. 如果希望传递一个空值,则应在从.NET代码执行该参数之前将DBNull.Value分配给该参数。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM