netX
netX

Reputation: 144

Procedure or function has too many arguments specified

Below is my stored procedure for insert:

CREATE PROCEDURE [dbo].[Insertaddress_Master]
(
@add_Zip    nvarchar(20),
@add_FullAddress    nvarchar(250),
@add_user_Id    int,
@add_CreatedDate    datetime,
@add_UpdatedDate    datetime,
@add_DeletedDate    datetime,
@add_IsDeleted  bit,
@add_IsPrimary  bit,
@add_cntm_Id    int,
@add_alt_No nvarchar(20)
)
As
BEGIN
SET NOCOUNT ON
Insert Into [address_Master]
(
[add_Zip],
[add_FullAddress],
[add_user_Id],
[add_CreatedDate],
[add_UpdatedDate],
[add_DeletedDate],
[add_IsDeleted],
[add_IsPrimary],
[add_cntm_Id],
[add_alt_No]
)
Values
(
@add_Zip,
@add_FullAddress,
@add_user_Id,
@add_CreatedDate,
@add_UpdatedDate,
@add_DeletedDate,
@add_IsDeleted,
@add_IsPrimary,
@add_cntm_Id,
@add_alt_No
)
END

Below is code behind function:

protected void AddNew(object sender, EventArgs e)
{
    try
    {
    address_MasterBM obj = new address_MasterBM();
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_Zip")).Text != "")
    {
        String add_Zipstr = ((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_Zip")).Text;
        obj.add_Zip = add_Zipstr;
    }
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_FullAddress")).Text != "")
    {
        String add_FullAddressstr = ((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_FullAddress")).Text;
        obj.add_FullAddress = add_FullAddressstr;
    }
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_user_Id")).Text != "")
    {
        Int32 add_user_Idstr = Convert.ToInt32(((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_user_Id")).Text);
        obj.add_user_Id = add_user_Idstr;
    }
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_CreatedDate")).Text != "")
    {
        DateTime add_CreatedDatestr = Convert.ToDateTime(((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_CreatedDate")).Text);
        obj.add_CreatedDate = add_CreatedDatestr;
    }
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_UpdatedDate")).Text != "")
    {
        DateTime add_UpdatedDatestr = Convert.ToDateTime(((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_UpdatedDate")).Text);
        obj.add_UpdatedDate = add_UpdatedDatestr;
    }
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_DeletedDate")).Text != "")
    {
        DateTime add_DeletedDatestr = Convert.ToDateTime(((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_DeletedDate")).Text);
        obj.add_DeletedDate = add_DeletedDatestr;
    }
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_IsDeleted")).Text != "")
    {
        Boolean add_IsDeletedstr = Convert.ToBoolean(((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_IsDeleted")).Text);
        obj.add_IsDeleted = add_IsDeletedstr;
    }
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_IsPrimary")).Text != "")
    {
        Boolean add_IsPrimarystr = Convert.ToBoolean(((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_IsPrimary")).Text);
        obj.add_IsPrimary = add_IsPrimarystr;
    }
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_cntm_Id")).Text != "")
    {
        Int32 add_cntm_Idstr = Convert.ToInt32(((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_cntm_Id")).Text);
        obj.add_cntm_Id = add_cntm_Idstr;
    }
    if (((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_alt_No")).Text != "")
    {
        String add_alt_Nostr = ((TextBox)gvaddress_Master.FooterRow.FindControl("txtadd_alt_No")).Text;
        obj.add_alt_No = add_alt_Nostr;
    }
    obj.Insertaddress_Master();
    BindData();
    lblException.Text = "";
    }
    catch(Exception ex)
    {
        lblException.Text = ex.Message.ToString();
    }
}

Below is business method code:

public void Insertaddress_Master() {
        try
        {
        DataAccess obj = new DataAccess();
        obj.Provider = EnumProviders.SQLClient;
        obj.ConnectionString = ConfigurationManager.ConnectionStrings["connStr"].ToString();
        ParamStruct[] param = new ParamStruct[10];
        param[0].direction = ParameterDirection.Input;
        param[0].ParamName = "@add_Zip";
        param[0].DataType = DbType.String;
        param[0].value = _add_Zip;
        param[1].direction = ParameterDirection.Input;
        param[1].ParamName = "@add_FullAddress";
        param[1].DataType = DbType.String;
        param[1].value = _add_FullAddress;
        param[2].direction = ParameterDirection.Input;
        param[2].ParamName = "@add_user_Id";
        param[2].DataType = DbType.Int32;
        param[2].value = _add_user_Id;
        param[3].direction = ParameterDirection.Input;
        param[3].ParamName = "@add_CreatedDate";
        param[3].DataType = DbType.DateTime;
        param[3].value = _add_CreatedDate;
        param[4].direction = ParameterDirection.Input;
        param[4].ParamName = "@add_UpdatedDate";
        param[4].DataType = DbType.DateTime;
        param[4].value = _add_UpdatedDate;
        param[5].direction = ParameterDirection.Input;
        param[5].ParamName = "@add_DeletedDate";
        param[5].DataType = DbType.DateTime;
        param[5].value = _add_DeletedDate;
        param[6].direction = ParameterDirection.Input;
        param[6].ParamName = "@add_IsDeleted";
        param[6].DataType = DbType.Boolean;
        param[6].value = _add_IsDeleted;
        param[7].direction = ParameterDirection.Input;
        param[7].ParamName = "@add_IsPrimary";
        param[7].DataType = DbType.Boolean;
        param[7].value = _add_IsPrimary;
        param[8].direction = ParameterDirection.Input;
        param[8].ParamName = "@add_cntm_Id";
        param[8].DataType = DbType.Int32;
        param[8].value = _add_cntm_Id;
        param[9].direction = ParameterDirection.Input;
        param[9].ParamName = "@add_alt_No";
        param[9].DataType = DbType.String;
        param[9].value = _add_alt_No;
            obj.ExecScalar("Insertaddress_Master", CommandType.StoredProcedure, param);             
            _returnBoolean = true;
        }
        catch (DataException ex) 
        {
            _returnBoolean = false;
            throw ex;
        }
    }

when I try to insert data using this code it generates exception saying " Procedure or function Insertaddress_Master has too many arguments specified". Can anyone help solving this problem.

I've read all previous thread on this topic but couldn't find appropriate solution yet.

Upvotes: 1

Views: 2614

Answers (2)

Vivek
Vivek

Reputation: 341

SqlCommand objCommand = new SqlCommand();

you can recreate this object then it will work.

Upvotes: 2

Dot_NET Pro
Dot_NET Pro

Reputation: 2123

I got this answer.

You have two fields:

Is Deleted
Is Primarry

You have to passed the boolean that may have true/false.

Try passing 1 for true and 0 for false.

This should do the trick

Upvotes: 0

Related Questions