过程或函数(存储过程名称)指定了太多参数

时间:2017-03-14 16:08:11

标签: sql-server vb.net stored-procedures

我知道这个问题已经得到解答,但我已经尝试了一些解决方案,但我仍然无法解决这个问题。

程序代码

USE [PROPERTY_MANAGEMENT_FOPMLIVE]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[create_budget1000] 
    -- Add the parameters for the stored procedure here
        @id varchar(36),
        @parentid varchar(36),
        @item nvarchar(47),
        @dsca nvarchar(255),
        @category nvarchar(255),
        @pid varchar(50),
        @companyid varchar(50),
        @subl int,
        --@amnt float,
        --@consumed float,
        --@balance float,
        @budget_type varchar(50),
        @fiscal_year int,
        @budget_description text,
        @active int,
        @budget_policy varchar(50),
        @budget_code nvarchar(36),
        @date_created datetime,
        @created_by varchar(36),
        @budget_for varchar(50),
        @gl_code varchar(50)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    INSERT INTO [dbo].[Budgets1000]
           ([id]
           ,[parentid]
           ,[item]
           ,[dsca]
           ,[category]
           ,[pid]
           ,[companyid]
           ,[subl]
           ,[amnt]
           ,[consumed]
           ,[balance]
           ,[budget_type]
           ,[fiscal_year]
           ,[budget_description]
           ,[active]
           ,[budget_policy]
           ,[budget_code]
           ,[date_created]
           ,[created_by]
           ,[budget_for]
           ,[gl_code])
     VALUES
           (@id
           ,@parentid
           ,@item
           ,@dsca
           ,@category
           ,@pid
           ,@companyid
           ,@subl
           ,0
           ,0
           ,0
           ,@budget_type
           ,@fiscal_year
           ,@budget_description
           ,@active
           ,@budget_policy
           ,@budget_code
           ,@date_created
           ,@created_by
           ,@budget_for
           ,@gl_code)
END

VB.Net代码

Public Sub createItem()
    Dim objConStr As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("TII")
    Dim Con As New SqlConnection(objConStr.ConnectionString)

    Dim IPAddress As String = Request.UserHostAddress
    Dim cmdsql2 As New SqlCommand
    cmdsql2.Connection = Con
    cmdsql2.CommandType = CommandType.StoredProcedure
    cmdsql2.CommandText = cs_properties.generate_replace_dbo_byproperty_id("[dbo].[create_budget]", Session("company_id"))

    Dim budgetID As String = Guid.NewGuid.ToString
    budgetID_hold = budgetID

    cmdsql2.Parameters.Add("@id", SqlDbType.VarChar)
    cmdsql2.Parameters("@id").Value = budgetID

    cmdsql2.Parameters.Add("@parentid", SqlDbType.VarChar)
    cmdsql2.Parameters("@parentid").Value = ddl_parent.SelectedValue

    If ddl_level.SelectedValue = "9" Then
        cmdsql2.Parameters.Add("@item", SqlDbType.NVarChar)
        cmdsql2.Parameters("@item").Value = "-"

        cmdsql2.Parameters.Add("@dsca", SqlDbType.NVarChar)
        cmdsql2.Parameters("@dsca").Value = txt_name.Text
    Else
        If ddl_budgetFor.SelectedValue = "Finance" Then
            cmdsql2.Parameters.Add("@item", SqlDbType.NVarChar)
            cmdsql2.Parameters("@item").Value = "-"

            cmdsql2.Parameters.Add("@dsca", SqlDbType.NVarChar)
            cmdsql2.Parameters("@dsca").Value = ddl_gl.SelectedValue

            cmdsql2.Parameters.Add("@category", SqlDbType.NVarChar)
            cmdsql2.Parameters("@category").Value = "-"
        Else
            If Session("company_id") = "1000" Then
                cmdsql2.Parameters.Add("@category", SqlDbType.NVarChar)
                cmdsql2.Parameters("@category").Value = "-"
            Else
                cmdsql2.Parameters.Add("@category", SqlDbType.NVarChar)
                cmdsql2.Parameters("@category").Value = ddl_category.SelectedValue
            End If

            cmdsql2.Parameters.Add("@item", SqlDbType.NVarChar)
            cmdsql2.Parameters("@item").Value = ddl_item.SelectedValue

            cmdsql2.Parameters.Add("@dsca", SqlDbType.NVarChar)
            cmdsql2.Parameters("@dsca").Value = ddl_item.SelectedItem.Text

        End If

    End If

    'cmdsql2.Parameters.Add("@category", SqlDbType.NVarChar)
    'cmdsql2.Parameters("@category").Value = ddl_category.SelectedValue

    cmdsql2.Parameters.Add("@pid", SqlDbType.VarChar)
    cmdsql2.Parameters("@pid").Value = "1"

    cmdsql2.Parameters.Add("@companyid", SqlDbType.VarChar)
    cmdsql2.Parameters("@companyid").Value = Session("company_id")

    cmdsql2.Parameters.Add("@subl", SqlDbType.Int)
    cmdsql2.Parameters("@subl").Value = ddl_level.SelectedValue

    cmdsql2.Parameters.Add("@budget_type", SqlDbType.VarChar)
    cmdsql2.Parameters("@budget_type").Value = Request.QueryString("budgettype")

    cmdsql2.Parameters.Add("@fiscal_year", SqlDbType.Int)
    cmdsql2.Parameters("@fiscal_year").Value = Request.QueryString("fiscalyear")

    cmdsql2.Parameters.Add("@budget_description", SqlDbType.Text)
    cmdsql2.Parameters("@budget_description").Value = ""

    cmdsql2.Parameters.Add("@active", SqlDbType.Int)
    cmdsql2.Parameters("@active").Value = 1

    cmdsql2.Parameters.Add("@budget_policy", SqlDbType.VarChar)
    cmdsql2.Parameters("@budget_policy").Value = Request.QueryString("budgetpolicy")

    cmdsql2.Parameters.Add("@budget_code", SqlDbType.NVarChar)
    cmdsql2.Parameters("@budget_code").Value = Request.QueryString("budgetcode")

    cmdsql2.Parameters.Add("@date_created", SqlDbType.DateTime)
    cmdsql2.Parameters("@date_created").Value = System.DateTime.Now

    cmdsql2.Parameters.Add("@created_by", SqlDbType.VarChar)
    cmdsql2.Parameters("@created_by").Value = Session("userid")

    If ddl_level.SelectedValue = "9" Then
        cmdsql2.Parameters.Add("@budget_for", SqlDbType.VarChar)
        cmdsql2.Parameters("@budget_for").Value = "-"
    Else
        cmdsql2.Parameters.Add("@budget_for", SqlDbType.VarChar)
        cmdsql2.Parameters("@budget_for").Value = ddl_budgetFor.SelectedItem.Text
    End If

    If ddl_budgetFor.SelectedItem.Text = "Finance" Then
        cmdsql2.Parameters.Add("@gl_code", SqlDbType.VarChar)
        cmdsql2.Parameters("@gl_code").Value = ddl_gl.SelectedValue

        'cmdsql2.Parameters.Add("@amnt", SqlDbType.VarChar)
        'cmdsql2.Parameters("@amnt").Value = finance_amount.Text

        cmdsql2.Parameters.Add("@category", SqlDbType.NVarChar)
        cmdsql2.Parameters("@category").Value = "-"
    Else
        cmdsql2.Parameters.Add("@gl_code", SqlDbType.VarChar)
        cmdsql2.Parameters("@gl_code").Value = "-"

        'cmdsql2.Parameters.Add("@amnt", SqlDbType.Float)
        'cmdsql2.Parameters("@amnt").Value = 0

        cmdsql2.Parameters.Add("@category", SqlDbType.NVarChar)
        cmdsql2.Parameters("@category").Value = ddl_category.SelectedValue

    End If

    'cmdsql2.Parameters.Add("@consumed", SqlDbType.Float)
    'cmdsql2.Parameters("@consumed").Value = 0

    'cmdsql2.Parameters.Add("@balance", SqlDbType.Float)
    'cmdsql2.Parameters("@balance").Value = 0

    If Con.State = ConnectionState.Closed Then Con.Open()
    Try
        cmdsql2.ExecuteNonQuery()
    Catch ex As Exception
        Response.Write("<script>alert('" & ex.Message & "');</script>")
    Finally
        If Con.State = ConnectionState.Open Then Con.Close()
        Con.Close()
    End Try

    SqlConnection.ClearPool(Con)
End Sub

我已经检查过我的代码是否在我的代码中正确填写了它看起来没问题,但是当我运行它时,它总是给我一个错误。

0 个答案:

没有答案