过程或函数指定了太多参数

时间:2014-03-13 07:54:52

标签: c# asp.net sql-server-2008 stored-procedures

下面是我的插入存储过程:

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

以下是功能背后的代码:

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();
    }
}

以下是业务方法代码:

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;
        }
    }

当我尝试使用此代码插入数据时,它会生成异常说"过程或函数Insertaddress_Master指定的参数太多"。谁能帮助解决这个问题。

我已阅读过有关此主题的所有先前帖子,但尚未找到合适的解决方案。

2 个答案:

答案 0 :(得分:1)

SqlCommand objCommand = new SqlCommand();

你可以重新创建这个对象,然后就可以了。

答案 1 :(得分:0)

我得到了这个答案。

您有两个字段:

Is Deleted
Is Primarry

你必须传递可能有true / false的布尔值。

尝试将1传递给true,将0传递给false。

这应该可以解决问题

相关问题