过程或函数需要参数,但未提供 [英] Procedure or function expects parameter, which was not supplied

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

问题描述

我调用一个简单的存储过程在SQL Server 2008中使用参数从c#,但它显示错误
过程或函数'AddYear'期望参数'@mYear',这不是

I am calling a simple stored procedure written in SQL Server 2008 with parameter from c# but it display error "Procedure or function 'AddYear' expects parameter '@mYear', which was not supplied."

这个程式码有什么问题,我尝试过几项但没有成功。

What's wrong with this code, i tried several things but didn't successed.

    SqlCommand AddEquip = new SqlCommand("AddYear", dbConn);
    SqlDataReader rdrEquip;

    SqlParameter mP = new SqlParameter("@mYear",SqlDbType.VarChar ) ;

    mP.Value = "1990";

    AddEquip.Parameters.Add(mP);


    rdrEquip = AddEquip.ExecuteReader();  

- 参数名称&类似于在过程中使用的。

-- Parameter Name & type are the same i use in the Procedure.

推荐答案

似乎您忘了设置 SqlCommand as store-procedure:

Seems like you forgot to set the SqlCommand as stored-procedure:

SqlCommand AddEquip = new SqlCommand("AddYear", dbConn);
AddEquip.CommandType = CommandType.StoredProcedure;

这篇关于过程或函数需要参数,但未提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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