错误:未提供过程和函数期望参数'@regdate'。 [英] Error:procedure and function expect parameter'@regdate', was not supplied.

查看:82
本文介绍了错误:未提供过程和函数期望参数'@regdate'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过程或函数需要参数'@Regdate'(datatpe-datetime),它不供应





我尝试过:



 ALTER PROCEDURE [dbo]。[sp_InsertLabreg] 

@patfor varchar(100)= null,
@LABID varchar(100)= null,
@pattypr varchar(100)= null,
@Reddate datetime,





 AS 
BEGIN

 INSERT INTO labreg 
(patfor,
LABID,
pattypr,
Regdate)



 INSERT INTO labreg 
(patfor,
LABID,
pattypr,
Regdate)结束

解决方案

看看您调用该过程的代码:您的前三个参数被标记为默认为NULL,这意味着如果您不提供值,则默认为OK。

但@Regdate没有默认值,意味着如果你不提供它,你将收到一个错误/>
您可以在定义中添加= NULL,但是......允许您向数据库发送完全空行...这可能不是一个好主意。


从C#调用SP的两个最常见问题是:



第一个不传递必需参数,因为OriginalGriff在其他答案中说明。



第二种是未能设置 SqlCommand.CommandType ,在这种情况下它将默认为Text。 pre lang =C#> 使用(SqlConnection conn = new SqlConnection(connectionString)){
使用(SqlCommand cmd = new SqlCommand({ProcedureName},conn)){
cmd .CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue( @ ParameterName,ParameterValue);
// 依此类推
}
}

SqlCommand.CommandType属性(系统.Data.SqlClient)| Microsoft Docs [ ^ ]


Procedure or Function expects parameter '@Regdate'(datatpe-datetime),which was not supply



What I have tried:

ALTER PROCEDURE [dbo].[sp_InsertLabreg] 
(
@patfor varchar(100)= null ,
        @LABID varchar(100)=null,
        @pattypr varchar(100)= null ,
        @Regdate datetime,


)

AS
BEGIN

INSERT INTO labreg
	(   patfor,
		LABID,
        pattypr,
        Regdate)

)

INSERT INTO labreg
	(   patfor,
		LABID,
        pattypr,
        Regdate) End

解决方案

Look at the code where you call the procedure: your first three parameters are marked as defaulting to NULL, which means if you don't provide a value, it defaults OK.
But @Regdate has no default, which means that if you don't supply it you will get an error.
You could add "= NULL" to the defintion, but ... that allows you to send completely blank rows to your DB ... which probably isn't a good idea.


The two most common issues in calling an SP from C# are:

The first is not passing in required parameters, as OriginalGriff states in the other answer.

The second is failing to set the SqlCommand.CommandType in which case it will default to Text.

using (SqlConnection conn = new SqlConnection(connectionString)) {
  using (SqlCommand cmd = new SqlCommand({ProcedureName}, conn)) {
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@ParameterName", ParameterValue);
    // and so on
   }
}

SqlCommand.CommandType Property (System.Data.SqlClient) | Microsoft Docs[^]


这篇关于错误:未提供过程和函数期望参数'@regdate'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆