【问题标题】:'Procedure or function insert_newemployee has too many arguments specified.''程序或函数 insert_newemployee 指定的参数太多。'
【发布时间】:2019-02-20 14:57:28
【问题描述】:

我有一个新员工注册页面,用于在此注册新员工

这是我将值传递给存储过程的地方

protected void btnbutton_Click(object sender, EventArgs e)
    {
        try
        {

            upload_photo();
            uploadfile();





                SqlCommand com = new SqlCommand("insert_newemployee", con);
                com.CommandType = System.Data.CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@firstname", txtfname.Text);
                com.Parameters.AddWithValue("@Lastname", txtlaname.Text);
                com.Parameters.AddWithValue("@Gender", ddlselect.SelectedValue.ToString());
                com.Parameters.AddWithValue("@DateofBirthday", txtdob.Text);
                com.Parameters.AddWithValue("@Mobilenumber", txtmnumber.Text);
                com.Parameters.AddWithValue("@Alternatenumber", txtanumber.Text);
                com.Parameters.AddWithValue("@Emailid", txtemail.Text);
                com.Parameters.AddWithValue("@AlternateEmail", txtaemail.Text);
                com.Parameters.AddWithValue("@Fathername", txtfaname.Text);
                com.Parameters.AddWithValue("@Mothername", txtmoname.Text);
                com.Parameters.AddWithValue("@AadhaarCardNo", txtacno.Text);
                com.Parameters.AddWithValue("@PanCardNo", txtpcno.Text);
                com.Parameters.AddWithValue("@PassportNo", txtpassno.Text);
                com.Parameters.AddWithValue("@UserName", txtuname.Text);
                com.Parameters.AddWithValue("@password", txtpwd.Text);
                com.Parameters.AddWithValue("@photo", ((ViewState["photoupload"].ToString() == null || ViewState["photoupload"].ToString() == "") ? "-" : ViewState["photoupload"].ToString()));
                com.Parameters.AddWithValue("@Otherfiles", ((ViewState["fileupload"].ToString() == null || ViewState["fileupload"].ToString() == "" ) ? "-" : ViewState["fileupload"].ToString()));
                com.Parameters.AddWithValue("@RAddressLine1", txtraline1.Text);
                com.Parameters.AddWithValue("@RAddressLine2", txtraline2.Text);
                com.Parameters.AddWithValue("@RCity", txtrcity.Text);
                com.Parameters.AddWithValue("@RState", txtrstate.Text);
                com.Parameters.AddWithValue("@RZipCode", txtrzcode.Text);
               com.Parameters.AddWithValue("@RCountry", txtrcountry.Text);
                com.Parameters.AddWithValue("@PAddressLine1", txtpaline1.Text);
                com.Parameters.AddWithValue("@PAddressLine2", txtpaline2.Text);
                com.Parameters.AddWithValue("@PCity", txtpcity.Text);
                com.Parameters.AddWithValue("@PState", txtpstate.Text);
                com.Parameters.AddWithValue("@PZipCode", txtpzcode.Text);
               com.Parameters.AddWithValue("@PCountry", txtpcountry.Text);
               com.Parameters.AddWithValue("@OAddressLine1", txtoaline1.Text);
                com.Parameters.AddWithValue("@OAddressLine2", txtoaline2.Text);
                com.Parameters.AddWithValue("@OCity", txtocity.Text);
                com.Parameters.AddWithValue("@OState", txtostate.Text);
                com.Parameters.AddWithValue("@OZipCode", txtozcode.Text);
                 com.Parameters.AddWithValue("@OCountry", txtocountry.Text);
                 com.Parameters.AddWithValue("@Createdby", Session["User_id"].ToString());
                com.Parameters.AddWithValue("@EmployeeId",Convert.ToInt32(ViewState["empseque"]));
                com.Parameters.AddWithValue("@result", SqlDbType.Int).Direction = ParameterDirection.Output;
                // com.Parameters.Add(sp4);
                con.Open();
                int output = com.ExecuteNonQuery();
                int result = Convert.ToInt32(com.Parameters["@result"].Value);
                con.Close();

                if (result == 1)
                {

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert(' Successfully Registered!');window.location.href = 'Newemployee.aspx'", true);
                }

                else if (result == 0)
                {

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Email Already Exist');", true);
                }

        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

    private void upload_photo()
    {
        if (uploadphoto.HasFile)
        {
            try
            {
                string photoupload = Path.GetFileName(uploadphoto.FileName);

                string photo_upload = DateTime.Now.ToString("yyyyMMddHHmmssfff") + photoupload ;
                ViewState["photoupload"] = photo_upload;


                uploadphoto.SaveAs(Server.MapPath("~/photoupload/") + photo_upload);


                string s = "1";
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert(' Only doc files are accepted!');", true);

            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert(' Exception : " + ex + "');", true);
            }
        }

    }

    private void uploadfile()
    {
        if (Uploadofiles.HasFile)
        {
            try
            {
                string file_upload = Path.GetFileName(Uploadofiles.FileName);

                string upload_file = DateTime.Now.ToString("yyyyMMddHHmmssfff") + file_upload ;
                ViewState["fileupload"] = upload_file;
                Uploadofiles.SaveAs(Server.MapPath("~/otherfileupload/") + upload_file);

                string s = "2";
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert(' Exception : " + ex + "');", true);
            }
        }

    }

这是我的存储过程

USE [PMS v1.0]
GO
/****** Object:  StoredProcedure [dbo].[insert_newemployee]    Script Date: 20-02-2019 09:57:56 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[insert_newemployee]
(

@firstname nvarchar(30),
@lastname nvarchar(20),
@Gender nvarchar(20),
@DateofBirthday date,
@password nvarchar(30),
@Fathername nvarchar(20),
@Mothername nvarchar(20),
@Mobilenumber nvarchar(20),
@Alternatenumber nvarchar(20),
@Emailid nvarchar(30),
@AlternateEmail nvarchar(30),
@AadhaarCardNo nvarchar(15),
@PanCardNo nvarchar(15),
@PassportNo nvarchar(15),
@UserName nvarchar(20),
@photo varchar(250),
@Otherfiles varchar(250),
@RAddressLine1 nvarchar(30),
@RAddressLine2 nvarchar(30),
@RCity nvarchar(30),
@RState nvarchar(15),
@RZipCode nvarchar(10),
@RCountry nvarchar(50),
@PAddressLine1 nvarchar(20),
@PAddressLine2 nvarchar(10),
@PCity nvarchar(10),
@PState nvarchar(10),
@PZipCode nvarchar(20),
@PCountry nvarchar(50),
@OAddressLine1 nvarchar(20),
@OAddressLine2 nvarchar(20),
@OCity nvarchar(30),
@OState nvarchar(30),
@OZipCode nvarchar(30),
@OCountry nvarchar(50),
@Createdby int,

@result int out
)

as
begin
if not exists(select Employeeid from newemployee where Emailid=@Emailid)
begin

insert into newemployee(
firstname,
lastname,
Gender,
DateofBirthday,
password,
Fathername,
Mothername,
Mobilenumber,
Alternatenumber,
Emailid,
AlternateEmail,
AadhaarCardNo,
PanCardNo,
PassportNo,
UserName,
photo,
Otherfiles,
RAddressLine1,
RAddressLine2,
RCity,
RState,
RZipCode,
RCountry,
PAddressLine1,
PAddressLine2,
PCity,
PState,
PZipCode,
PCountry,
OAddressLine1,
OAddressLine2,
OCity,
OState,
OZipCode,
OCountry,
Createdby)
values(
@firstname,
@lastname,
@Gender,
@DateofBirthday,
@password,
@Fathername,
@Mothername,
@Mobilenumber,
@Alternatenumber,
@Emailid,
@AlternateEmail,
@AadhaarCardNo,
@PanCardNo,
@PassportNo,
@UserName,
@photo,
@Otherfiles,
@RAddressLine1,
@RAddressLine2,
@RCity,
@RState,
@RZipCode,
@RCountry,
@PAddressLine1,
@PAddressLine2,
@PCity,
@PState,
@PZipCode,
@PCountry,
@OAddressLine1,
@OAddressLine2,
@OCity,
@OState,
@OZipCode,
@OCountry,
@Createdby)

set @result=1

end
else
begin

set @result=0

end

end

我已经检查了很多次,这两个值都是一样的。

【问题讨论】:

  • 根据错误 Procedure or function insert_newemployee has too many arguments specified. 表示从您的应用程序传递给名为 insert_newemployee 的 SQL 服务器过程的参数数量( 即 39)超过了过程支持的参数数量(即 38 根据您的代码)。所以,我认为您可能在您的应用程序代码中定义了一个额外的参数,或者在您的过程中没有定义一个参数。
  • 和仅供参考,从您的应用代码传递的名为 @EmployeeId 的参数在过程中不可用。

标签: c# asp.net visual-studio stored-procedures


【解决方案1】:

查询有 37 个参数,提供了 38 个参数。我的猜测是,如果它最初是有效的,那么有人已经改变了程序。 每当我收到此错误时(由于在许多不同的应用程序中使用 SP 并且许多不同的人更改它们而经常发生),我将参数从代码和 sql 复制到 notepad++ 并进行比较。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多