| | |
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:
Solved Threads: 0
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'.
VB.NET Syntax (Toggle Plain Text)
Private Sub ButtonReconsilation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReconsilation.Click Dim connection As SqlConnection = database_connection() connection.Open() Dim count, I As Integer I = 0 Try Dim command As SqlCommand = New SqlCommand("insertCashBook", connection) command.CommandType = CommandType.StoredProcedure count = LoadCashBookDataSet.Tables(0).Rows.Count While I < count 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 I = I + 1 End While command.ExecuteNonQuery() 'Receive Error while execute this statement Catch ex As Exception MsgBox(Err.Description) End Try End Sub
Last edited by Ancient Dragon; Feb 4th, 2009 at 9:33 am. Reason: add code tags
•
•
Join Date: Nov 2008
Posts: 63
Reputation:
Solved Threads: 10
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)
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.
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Viewing Data in Datagrid
- Next Thread: hi its aruna
| Thread Tools | Search this Thread |
.net .net2005 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dissertationthesis dropdownlist excel fade file-dialog folder ftp generatetags google gridview hardcopy image images input insert intel internet mobile monitor ms net networking objects output passingparameters peertopeervideostreaming picturebox picturebox1 port print problem problemwithinstallation project reports" save savedialog searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer toolbox trim update updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf





