Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good day,

when i run my project, this error appears in my catch "Procedure or function sp_CreditNoteGSTInsert has too many arguments specified."

////this is my vb code:

VB
Public Function InsertCommandCreditNote(ByVal strCreditNoteNo As String, ByVal strCreditNoteDate As String, _
                                          ByVal strBranchCode As String, ByVal strCustomerAccNo As String, ByVal strCustomer As String, _
                                          ByVal strInvoiceNo As String, ByVal intInvoiceID As Integer, _
                                          ByVal totalAmount As Double, ByVal guidUserID As Guid, ByVal roundAdjustment As Double) As Integer

       Dim result As Integer = 0
       Try

           Dim conn As New SqlConnection(conStrBuilder.ConnectionString)

           conn.Open()

           Dim myCommand As New SqlCommand
           myCommand = New SqlCommand("sp_CreditNoteGSTInsert", conn)
           myCommand.CommandType = CommandType.StoredProcedure

           Dim myParamCreditNoteNo As New SqlParameter
           myParamCreditNoteNo = New SqlParameter("strCreditNoteNo", SqlDbType.NVarChar, 25)
           myParamCreditNoteNo.Value = strCreditNoteNo
           myParamCreditNoteNo.Direction = ParameterDirection.Input

           Dim myParamCreditNoteDate As New SqlParameter
           myParamCreditNoteDate = New SqlParameter("dteCreditNoteDate", SqlDbType.DateTime)
           myParamCreditNoteDate.Value = strCreditNoteDate
           myParamCreditNoteDate.Direction = ParameterDirection.Input

           Dim myParamBranchCode As New SqlParameter
           myParamBranchCode = New SqlParameter("strBranchCode", SqlDbType.NChar, 10)
           myParamBranchCode.Value = strBranchCode
           myParamBranchCode.Direction = ParameterDirection.Input

           Dim myParamCustomerAccNo As New SqlParameter
           myParamCustomerAccNo = New SqlParameter("strCustomerAccNo", SqlDbType.NVarChar, 30)
           myParamCustomerAccNo.Value = strCustomerAccNo
           myParamCustomerAccNo.Direction = ParameterDirection.Input

           Dim myParamCustomer As New SqlParameter
           myParamCustomer = New SqlParameter("strCustomer", SqlDbType.NVarChar, 80)
           myParamCustomer.Value = strCustomer
           myParamCustomer.Direction = ParameterDirection.Input

           Dim myParamInvoiceID As New SqlParameter
           myParamInvoiceID = New SqlParameter("intInvoiceID", SqlDbType.Int)
           myParamInvoiceID.Value = intInvoiceID
           myParamInvoiceID.Direction = ParameterDirection.Input

           Dim myParamTotalAmount As New SqlParameter
           myParamTotalAmount = New SqlParameter("dblCreditNoteTotalAmount", SqlDbType.Money)
           myParamTotalAmount.Value = totalAmount
           myParamTotalAmount.Direction = ParameterDirection.Input

           Dim myParamguidUserID As New SqlParameter
           myParamguidUserID = New SqlParameter("guidUserID", SqlDbType.UniqueIdentifier)
           myParamguidUserID.Value = guidUserID
           myParamguidUserID.Direction = ParameterDirection.Input

           Dim myParamRoundAdjustment As New SqlParameter
           myParamRoundAdjustment = New SqlParameter("dblroundadj", SqlDbType.Money)
           myParamRoundAdjustment.Value = roundAdjustment
           myParamRoundAdjustment.Direction = ParameterDirection.Input

           myCommand.Parameters.Add(myParamCreditNoteNo)
           mycommand.Parameters.Add(myParamCreditNoteDate)
           mycommand.Parameters.Add(myParamBranchCode)
           mycommand.Parameters.Add(myParamCustomerAccNo)
           mycommand.Parameters.Add(myParamCustomer)
           mycommand.Parameters.Add(myParamInvoiceID)
           mycommand.Parameters.Add(myParamTotalAmount)
           mycommand.Parameters.Add(myParamguidUserID)
           mycommand.Parameters.Add(myParamRoundAdjustment)

           Dim mySqlDataAdapter As SqlDataAdapter
           mySqlDataAdapter = New SqlDataAdapter(myCommand)

           Dim myDataSet As New DataSet
           mySqlDataAdapter.Fill(myDataSet, "tblCreditNote")

           conn.Close()

           result = 1

       Catch ex As Exception

           objTracer.WriteToLog(ex.ToString())

       End Try
       Return result
   End Function



///and this is my store procedure:

SQL
ALTER PROCEDURE [dbo].[sp_CreditNoteGSTInsert]
	@strCreditNoteNo nvarchar(25), 
    @dteCreditNoteDate datetime, 
    @strBranchCode nchar(10), 
    @strCustomerAccNo nvarchar(30),
    @strCustomer nvarchar(80), 
    @intInvoiceID int,
    @dblCreditNoteTotalAmount money,
    @guidUserID uniqueidentifier
AS
BEGIN

	SET NOCOUNT ON;

DECLARE @TotalPayment AS MONEY
SET @TotalPayment = (SELECT SUM(round(Total,2)) FROM tblCreditNoteDetails_GST WHERE CreditNote_No = @strCreditNoteNo AND IsDeleted = 0)

INSERT INTO tblCreditNote(
 CreditNote_No
,CreditNote_Date
,CreditNote_Branch_Code
,Customer_Acc_No
,Customer_Name
,Invoice_No
,CreditNote_Total_Amount
,IsDeleted
,SysCreatedBy
,SysCreatedOn
)
VALUES
(
 @strCreditNoteNo
,@dteCreditNoteDate
,@strBranchCode
,@strCustomerAccNo
,@strCustomer
,@intInvoiceID
,@dblCreditNoteTotalAmount
,0
,@guidUserID
,GETDATE()
)




any suggestion how can i fix this error?

Thank you very much.

What I have tried:

i did try to use this method but still return me error.

vb.net - Procedure or Function has Too many arguments specified - Stack Overflow[^]
Posted
Updated 25-Apr-16 15:25pm
v3

Well...if you look:
C#
myCommand.Parameters.Add(myParamCreditNoteNo)
mycommand.Parameters.Add(myParamCreditNoteDate)
mycommand.Parameters.Add(myParamBranchCode)
mycommand.Parameters.Add(myParamCustomerAccNo)
mycommand.Parameters.Add(myParamCustomer)
mycommand.Parameters.Add(myParamInvoiceID)
mycommand.Parameters.Add(myParamTotalAmount)
mycommand.Parameters.Add(myParamguidUserID)
mycommand.Parameters.Add(myParamRoundAdjustment)
9 parameters
SQL
ALTER PROCEDURE [dbo].[sp_CreditNoteGSTInsert]
@strCreditNoteNo nvarchar(25), 
@dteCreditNoteDate datetime, 
@strBranchCode nchar(10), 
@strCustomerAccNo nvarchar(30),
@strCustomer nvarchar(80), 
@intInvoiceID int,
@dblCreditNoteTotalAmount money,
@guidUserID uniqueidentifier
AS
BEGIN
8 Parameters.
So either you need to change your SP to accept one more parameter, or you need to remove the myParamRoundAdjustment when you call it.


BTW: I'd strongly suggest you look at Parameters.AddWithValue instead of creating it yourself and calling Parameters.Add - it'll make your code a whole lot cleaner and easier to read.
 
Share this answer
 
Comments
Patrice T 25-Apr-16 5:29am    
5ed
It just a matter of reading your code
The stored procedure expect
SQL
@strCreditNoteNo nvarchar(25),
@dteCreditNoteDate datetime,
@strBranchCode nchar(10),
@strCustomerAccNo nvarchar(30),
@strCustomer nvarchar(80),
@intInvoiceID int,
@dblCreditNoteTotalAmount money,
@guidUserID uniqueidentifier

and your parameters are
VB
myCommand.Parameters.Add(myParamCreditNoteNo)
mycommand.Parameters.Add(myParamCreditNoteDate)
mycommand.Parameters.Add(myParamBranchCode)
mycommand.Parameters.Add(myParamCustomerAccNo)
mycommand.Parameters.Add(myParamCustomer)
mycommand.Parameters.Add(myParamInvoiceID)
mycommand.Parameters.Add(myParamTotalAmount)
mycommand.Parameters.Add(myParamguidUserID)
mycommand.Parameters.Add(myParamRoundAdjustment)

The problem is that they don't match.
 
Share this answer
 
Hi,

I have checked and find out that you have adding Sql parameter
C#
mycommand.Parameters.Add(myParamRoundAdjustment)

from code but in procedure you don't have declare this parameter.
 
Share this answer
 
v2
thank you very much all. all your solution are working properly, i didn't expect i can miss something like this.

thank you very much.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900