过程或函数指定了太多参数。 [英] Procedure or function has too many arguments specified.

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

问题描述

我正在尝试使用SP插入数据,如下所示:



  ALTER   PROCEDURE  [dbo]。[AddTrainingRoomRq] 

@ req_start_date DateTime
@ req_end_date DateTime
@ req_times text
@requestor_name text
@ requestor_phone text
@ requestor_mail_symbol text
@ requestor_email text
@ class_name text
@ user_num text
@ other_software text
@internet_access
@ intranet_access 位<​​/ span>,
@ other_logons 位<​​/ span>,
@ other_logon_list text
@ additional_comments varchar 500 ),
@ Result nvarchar 500 输出

AS
BEGIN

< span class =code-keyword>声明


@ ClassID int

设置 @ ClassID =( SELECT CAST(RAND()* 1000000000 AS INT AS [RandomNumber])

INSERT INTO cal_tr_requests
(ClassID,req_start_date,req_end_date,req_times,requestor_name,requestor_phone,requestor_mail_symbol,requestor_email,class_name,user_num,other_software,
internet_access,intranet_access,other_logons,other_logon_list,additional_comments,date_of_req)
VALUES @ ClassID ,< span class =code-sdkkeyword> @ req_start_ date
@ req_end_date @ req_times @requestor_name @ requestor_phone @ requestor_mail_symbol @requestor_email @ class_name @ user_num @other_software
@internet_access @ intranet_access @ other_logons @ other_logon_list @ additional_comments ,getdate( ))

设置 @ Result = 转换 nvarchar @ Clas sID

END



我的代码背后:

< pre lang =c#{
public partial class trainingroom:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
String strSysDt = Convert.ToString(System.DateTime.Now);
}

protected void lbInsert_Click(object sender,EventArgs e)
{
string strReqNm =((TextBox)fvAddBookingInfo.FindControl(txtReqName))。Text ;
string strPhone =((TextBox)fvAddBookingInfo.FindControl(txtPhone))。文本;
string strMailSymbol =((TextBox)fvAddBookingInfo.FindControl(txtMailSym))。文本;
string strEmail =((TextBox)fvAddBookingInfo.FindControl(txtEmail))。Text;
string strFirstDt =((TextBox)fvAddBookingInfo.FindControl(txtFirstDt))。Text;
string strLastDt =((TextBox)fvAddBookingInfo.FindControl(txtLastDt))。Text;
string strUseTime =((TextBox)fvAddBookingInfo.FindControl(txtUseTime))。Text;
string strClassTy =((TextBox)fvAddBookingInfo.FindControl(txtClass))。Text;
string strNumOfUsr =((TextBox)fvAddBookingInfo.FindControl(txtNumOfUsr))。文本;
string strOtherSW =((TextBox)fvAddBookingInfo.FindControl(txtOtherSW))。文本;
CheckBox ckInternet =(CheckBox)fvAddBookingInfo.FindControl(cbInternet);
CheckBox ckIntranet =(CheckBox)fvAddBookingInfo.FindControl(cbIntranet);
CheckBox ckOthrLog =(CheckBox)fvAddBookingInfo.FindControl(cbOtherLog);
string strListOthLog =((TextBox)fvAddBookingInfo.FindControl(txtOtherLogList))。Text;
string strComment =((TextBox)fvAddBookingInfo.FindControl(txtComment))。Text;
String strSysDt = Convert.ToString(System.DateTime.Now);

SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings [CFMAppsConnectionString]。ConnectionString;
cmd.Connection = conn;
cmd.CommandText =AddTrainingRoomRq;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(@ requestor_name,SqlDbType.NVarChar).Value = strReqNm;
cmd.Parameters.Add(@ requestor_phone,SqlDbType.NVarChar).Value = strPhone;
cmd.Parameters.Add(@ requestor_mail_symbol,SqlDbType.NVarChar).Value = strMailSymbol;
cmd.Parameters.Add(@ requestor_email,SqlDbType.NVarChar).Value = strEmail;
cmd.Parameters.Add(@ req_start_date,SqlDbType.DateTime).Value = strFirstDt;
cmd.Parameters.Add(@ req_end_date,SqlDbType.DateTime).Value = strLastDt;
cmd.Parameters.Add(@ req_times,SqlDbType.NVarChar).Value = strUseTime;
cmd.Parameters.Add(@ class_name,SqlDbType.NVarChar).Value = strClassTy;
cmd.Parameters.Add(@ user_num,SqlDbType.NVarChar).Value = strNumOfUsr;
cmd.Parameters.Add(@ other_software,SqlDbType.NVarChar).Value = strOtherSW;
cmd.Parameters.Add(@ other_logon_list,SqlDbType.NVarChar).Value = strListOthLog;
cmd.Parameters.Add(@ additional_comments,SqlDbType.NVarChar).Value = strComment;
cmd.Parameters.Add(@ date_of_req,SqlDbType.DateTime).Value = strSysDt;
if(ckInternet.Checked)
{
cmd.Parameters.Add(@ internet_access,SqlDbType.Bit).Value = 1;
}
else
{
cmd.Parameters.Add(@ internet_access,SqlDbType.Bit).Value = 0;
}
if(ckIntranet.Checked)
{
cmd.Parameters.Add(@ intranet_access,SqlDbType.Bit).Value = 1;
}
else
{
cmd.Parameters.Add(@ intranet_access,SqlDbType.Bit).Value = 0;
}
if(ckOthrLog.Checked)
{
cmd.Parameters.Add(@ other_logons,SqlDbType.Bit).Value = 1;
}
else
{
cmd.Parameters.Add(@ other_logons,SqlDbType.Bit).Value = 0;
}
//cmd.Parameters.Add(\"@Result,SqlDbType.NVarChar,500).Direction = ParameterDirection.Output;
//cmd.Parameters(\"@Result\").Direction = ParameterDirection.Output;
SqlParameter outPutParameter = new SqlParameter();
outPutParameter.ParameterName =@ Result;
outPutParameter.SqlDbType = System.Data.SqlDbType.NVarChar;
outPutParameter.Size = 500;
outPutParameter.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter);

conn.Open();
cmd.ExecuteNonQuery();
//cmd.ExecuteScalar();
conn.Close();
string Result = outPutParameter.Value.ToString();
lblResultMsg.Text =结果;
//lblResultMsg.Text = cmd.Parameters [@ Result]。Value.ToString();

}

}
}>





我是得到错误:过程或函数指定了太多参数。

请帮助!



我尝试了什么:



我搜索并尝试了一些解决方案但没有成功。

解决方案

Quote:

请帮忙!

首先帮助自己!

It是计数问题!

错误消息告诉您SQL过程需要许多参数,并且调用程序提供不同数量的参数。



解决方案:自己动手并比较2个参数列表,逐行检查,检查两侧的参数名称(1个字符差异,但不匹配)。

它可以帮助两边的参数顺序相同。


@date_of_req isn T A列出的参数。

I am trying to insert data using a SP as follows:

ALTER PROCEDURE [dbo].[AddTrainingRoomRq]

@req_start_date DateTime,
@req_end_date DateTime,
@req_times text,
@requestor_name text,
@requestor_phone text,
@requestor_mail_symbol text,
@requestor_email text,
@class_name text,
@user_num text,
@other_software text,
@internet_access bit,
@intranet_access bit,
@other_logons bit,
@other_logon_list text,
@additional_comments varchar (500),
@Result nvarchar (500) output

AS
BEGIN

Declare 

@ClassID int

Set @ClassID = 	(SELECT CAST(RAND() * 1000000000 AS INT) AS [RandomNumber])

INSERT INTO cal_tr_requests
           (ClassID, req_start_date, req_end_date, req_times, requestor_name, requestor_phone, requestor_mail_symbol, requestor_email, class_name, user_num, other_software, 
		   internet_access, intranet_access, other_logons, other_logon_list, additional_comments, date_of_req)
VALUES        (@ClassID,@req_start_date,@req_end_date,@req_times,@requestor_name,@requestor_phone,@requestor_mail_symbol,@requestor_email,@class_name,@user_num,@other_software,
              @internet_access,@intranet_access,@other_logons,@other_logon_list,@additional_comments,getdate())

Set @Result = Convert(nvarchar,@ClassID)

END


My code behind:

<pre lang="c#"{
    public partial class trainingroom : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String strSysDt = Convert.ToString(System.DateTime.Now);
        }

        protected void lbInsert_Click(object sender, EventArgs e)
        {
            string strReqNm = ((TextBox)fvAddBookingInfo.FindControl("txtReqName")).Text;
            string strPhone = ((TextBox)fvAddBookingInfo.FindControl("txtPhone")).Text;
            string strMailSymbol = ((TextBox)fvAddBookingInfo.FindControl("txtMailSym")).Text;
            string strEmail = ((TextBox)fvAddBookingInfo.FindControl("txtEmail")).Text;
            string strFirstDt = ((TextBox)fvAddBookingInfo.FindControl("txtFirstDt")).Text;
            string strLastDt = ((TextBox)fvAddBookingInfo.FindControl("txtLastDt")).Text;
            string strUseTime = ((TextBox)fvAddBookingInfo.FindControl("txtUseTime")).Text;
            string strClassTy = ((TextBox)fvAddBookingInfo.FindControl("txtClass")).Text;
            string strNumOfUsr = ((TextBox)fvAddBookingInfo.FindControl("txtNumOfUsr")).Text;
            string strOtherSW = ((TextBox)fvAddBookingInfo.FindControl("txtOtherSW")).Text;
            CheckBox ckInternet = (CheckBox)fvAddBookingInfo.FindControl("cbInternet");
            CheckBox ckIntranet = (CheckBox)fvAddBookingInfo.FindControl("cbIntranet");
            CheckBox ckOthrLog = (CheckBox)fvAddBookingInfo.FindControl("cbOtherLog");
            string strListOthLog = ((TextBox)fvAddBookingInfo.FindControl("txtOtherLogList")).Text;
            string strComment = ((TextBox)fvAddBookingInfo.FindControl("txtComment")).Text;
            String strSysDt = Convert.ToString(System.DateTime.Now);

            SqlConnection conn = new SqlConnection();
            SqlCommand cmd = new SqlCommand();
            conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["CFMAppsConnectionString"].ConnectionString;
            cmd.Connection = conn;
            cmd.CommandText = "AddTrainingRoomRq";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add("@requestor_name", SqlDbType.NVarChar).Value = strReqNm;
            cmd.Parameters.Add("@requestor_phone", SqlDbType.NVarChar).Value = strPhone;
            cmd.Parameters.Add("@requestor_mail_symbol", SqlDbType.NVarChar).Value = strMailSymbol;
            cmd.Parameters.Add("@requestor_email", SqlDbType.NVarChar).Value = strEmail;
            cmd.Parameters.Add("@req_start_date", SqlDbType.DateTime).Value = strFirstDt;
            cmd.Parameters.Add("@req_end_date", SqlDbType.DateTime).Value = strLastDt;
            cmd.Parameters.Add("@req_times", SqlDbType.NVarChar).Value = strUseTime;
            cmd.Parameters.Add("@class_name", SqlDbType.NVarChar).Value = strClassTy;
            cmd.Parameters.Add("@user_num", SqlDbType.NVarChar).Value = strNumOfUsr;
            cmd.Parameters.Add("@other_software", SqlDbType.NVarChar).Value = strOtherSW;
            cmd.Parameters.Add("@other_logon_list", SqlDbType.NVarChar).Value = strListOthLog;
            cmd.Parameters.Add("@additional_comments", SqlDbType.NVarChar).Value = strComment;
            cmd.Parameters.Add("@date_of_req", SqlDbType.DateTime).Value = strSysDt;
            if (ckInternet.Checked)
            {
                cmd.Parameters.Add("@internet_access", SqlDbType.Bit).Value = 1;
            }
            else
            {
                cmd.Parameters.Add("@internet_access", SqlDbType.Bit).Value = 0;
            }
            if (ckIntranet.Checked)
            {
                cmd.Parameters.Add("@intranet_access", SqlDbType.Bit).Value = 1;
            }
            else
            {
                cmd.Parameters.Add("@intranet_access", SqlDbType.Bit).Value = 0;
            }
            if (ckOthrLog.Checked)
            {
                cmd.Parameters.Add("@other_logons", SqlDbType.Bit).Value = 1;
            }
            else
            {
                cmd.Parameters.Add("@other_logons", SqlDbType.Bit).Value = 0;
            }
            //cmd.Parameters.Add("@Result", SqlDbType.NVarChar, 500).Direction = ParameterDirection.Output;
            //cmd.Parameters("@Result").Direction = ParameterDirection.Output;
            SqlParameter outPutParameter = new SqlParameter();
            outPutParameter.ParameterName = "@Result";
            outPutParameter.SqlDbType = System.Data.SqlDbType.NVarChar;
            outPutParameter.Size = 500;
            outPutParameter.Direction = System.Data.ParameterDirection.Output;
            cmd.Parameters.Add(outPutParameter);
            
            conn.Open();
            cmd.ExecuteNonQuery();
            //cmd.ExecuteScalar();           
            conn.Close();
            string Result = outPutParameter.Value.ToString();
            lblResultMsg.Text = Result;
            //lblResultMsg.Text = cmd.Parameters["@Result"].Value.ToString();

        }

    }
}>



I am getting error: Procedure or function has too many arguments specified.
Please help!

What I have tried:

I searched and tried a few solution without success.

解决方案

Quote:

Please help!

Start by helping yourself!
It is a matter of counting !
The error message tells you that the SQL procedure expect a number of parameters and that the calling program gives a different number of parameters.

the solution: Take yourself by the hand and compare the 2 list of parameters, check line by line, check the parameter name on both sides ( 1 char difference and it don't match).
It can help to have the parameters in same order on both sides.


@date_of_req isn't a listed parameter.


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

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