Procedure or function insertCashBook has too many arguments specified.

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2009
Posts: 12
Reputation: farooq82 is an unknown quantity at this point 
Solved Threads: 0
farooq82 farooq82 is offline Offline
Newbie Poster

Procedure or function insertCashBook has too many arguments specified.

 
0
  #1
Feb 3rd, 2009
I am new vb.net and I m working on project that will import excel file in datagrid. After import this file I need to save these file into SQL Server 2005 table. But I am receiving 'Procedure or function insertCashBook has too many arguments specified'.
  1. Private Sub ButtonReconsilation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReconsilation.Click
  2.  
  3. Dim connection As SqlConnection = database_connection()
  4. connection.Open()
  5.  
  6. Dim count, I As Integer
  7.  
  8. I = 0
  9. Try
  10. Dim command As SqlCommand = New SqlCommand("insertCashBook", connection)
  11. command.CommandType = CommandType.StoredProcedure
  12.  
  13. count = LoadCashBookDataSet.Tables(0).Rows.Count
  14. While I < count
  15. If NZ(LoadCashBookDataSet.Tables(0).Rows(I)(4)) = 0 Then
  16. command.Parameters.AddWithValue("@DR", NZ(LoadCashBookDataSet.Tables(0).Rows(I)(4)))
  17. command.Parameters.AddWithValue("@CR", Convert.ToDecimal(LoadCashBookDataSet.Tables(0).Rows(I)(5)))
  18.  
  19. ElseIf NZ(LoadCashBookDataSet.Tables(0).Rows(I)(5)) = 0 Then
  20. command.Parameters.AddWithValue("@CR", NZ(LoadCashBookDataSet.Tables(0).Rows(I)(4)))
  21. command.Parameters.AddWithValue("@DR", Convert.ToDecimal(LoadCashBookDataSet.Tables(0).Rows(I)(4)))
  22.  
  23. Else
  24. command.Parameters.AddWithValue("@DR", Convert.ToDecimal(LoadCashBookDataSet.Tables(0).Rows(I)(4)))
  25. command.Parameters.AddWithValue("@CR", Convert.ToDecimal(LoadCashBookDataSet.Tables(0).Rows(I)(5)))
  26. End If
  27.  
  28. I = I + 1
  29. End While
  30.  
  31. command.ExecuteNonQuery() 'Receive Error while execute this statement
  32. Catch ex As Exception
  33. MsgBox(Err.Description)
  34. End Try
  35.  
  36. End Sub
Last edited by Ancient Dragon; Feb 4th, 2009 at 9:33 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: Procedure or function insertCashBook has too many arguments specified.

 
0
  #2
Feb 3rd, 2009
You must have 2 parameters declared in your Stored Procedure, called @DR and @CR, both of the type Decimal.
While looping through your rows in your LoadCashBookDataSet.Tables(0) you have to execute the command based on the stored procedure & active connection. So, each time you have passed a row, you have to execute the command in order to update your databasetable.

This means you have to try something like this: (the code should be cleaned up & added with cleanup code for your unmanaged objects like the connection and command)

Private Sub ButtonReconsilation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReconsilation.Click

Dim connection As SqlConnection = database_connection()
Try
    connection.Open()
Catch ex as exception
   msgbox ex.message
End Try

Dim count as integer = 0
dim I As Integer = 0
Dim command As SqlCommand = nothing

Try

count = LoadCashBookDataSet.Tables(0).Rows.Count
While I < count
command= New SqlCommand("insertCashBook", connection)
command.CommandType = CommandType.StoredProcedure


If NZ(LoadCashBookDataSet.Tables(0).Rows(I)(4)) = 0 Then
command.Parameters.AddWithValue("@DR", NZ(LoadCashBookDataSet.Tables(0).Rows(I)(4)))
command.Parameters.AddWithValue("@CR", Convert.ToDecimal(LoadCashBookDataSet.Tables(0).Rows(I)(5)))

ElseIf NZ(LoadCashBookDataSet.Tables(0).Rows(I)(5)) = 0 Then
command.Parameters.AddWithValue("@CR", NZ(LoadCashBookDataSet.Tables(0).Rows(I)(4)))
command.Parameters.AddWithValue("@DR", Convert.ToDecimal(LoadCashBookDataSet.Tables(0).Rows(I)(4)))

Else
command.Parameters.AddWithValue("@DR", Convert.ToDecimal(LoadCashBookDataSet.Tables(0).Rows(I)(4)))
command.Parameters.AddWithValue("@CR", Convert.ToDecimal(LoadCashBookDataSet.Tables(0).Rows(I)(5)))
End If
command.ExecuteNonQuery() 
'I = I + 1
I += 1
End While

'Receive Error while execute this statement 
Catch ex As Exception
MsgBox(Err.Description)
End Try

End Sub
Last edited by 4advanced; Feb 3rd, 2009 at 1:34 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 12
Reputation: farooq82 is an unknown quantity at this point 
Solved Threads: 0
farooq82 farooq82 is offline Offline
Newbie Poster

Re: Procedure or function insertCashBook has too many arguments specified.

 
0
  #3
Feb 3rd, 2009
thx dear its works
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC