“过程或函数insert_newemployee指定的参数过多。”

时间:2019-02-20 05:11:18

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

我有一个新的员工注册页面,用于在此页面上注册新员工。我已经使用存储过程将数据插入数据库中,现在我收到此错误,之前它运行正常

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

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

我已经多次检查了这两个值是否相同。

1 个答案:

答案 0 :(得分:0)

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