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
<strong>I += 1</strong>
End While
'Receive Error while execute this statement
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub 4advanced
Junior Poster in Training
67 posts since Nov 2008
Reputation Points: 33
Solved Threads: 10