stephen2005
Programmer
I'm using a stored proceedure which should update a number of rows in a table depending on a key value supplied (in this case 'JobID'). But what's happening is when I call the proc from within the program, only one row gets updated.
So
When I call the proc from Query Analyser, all rows get updated.
When I call the proc from within the program, only one row gets updated
Any ideas as to why this is happening??
JobID Description Price Status
----------------------------------------------
73412 Documents:Item 3 .00 0
73412 Documents:Item 5 .00 0
73412 Documents:Item 2 .00 0
73412 Documents:Item 4 .00 0
73412 Documents:Item 1 .00 0
^^^^Only one record gets updated, so the table ends up being...
JobID Description Price Status
----------------------------------------------
73412 Documents:Item 3 .00 4
73412 Documents:Item 5 .00 0
73412 Documents:Item 2 .00 0
73412 Documents:Item 4 .00 0
73412 Documents:Item 1 .00 0
Public Sub UpdateAllItems() As Boolean
Dim objCnn As ADODB.Connection
Dim objCmd As ADODB.Command
Set objCnn = New ADODB.Connection
With objCnn
.ConnectionString = cnConn
.CursorLocation = adUseClient
.Open
End With
Set objCmd = New ADODB.Command
Set objCmd.ActiveConnection = objCnn
With objCmd
.CommandText = "sp_UpdateJobItem"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@Status", adInteger, adParamInput, 4, Me.Status)
.Parameters.Append .CreateParameter("@JobID", adInteger, adParamInput, 4, Me.iJobID)
.Execute
End With
Set objCnn = Nothing
Set objCmd = Nothing
End Sub
-----------------------------------------------------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE dbo.sp_UpdateJobItem
@JobID As int
, @Status As int
AS
-- =============================================================================================
SET XACT_ABORT OFF -- Allow procedure to continue after error
DECLARE @error integer -- Local variable to capture the error OnHoldAction.
-- =============================================================================================
BEGIN TRANSACTION
UPDATE tbl_JobItems
SET Status = @status
WHERE JobID = @JobID
-- =============================================================================================
-- Check for errors
-- =============================================================================================
SELECT @error = @ERROR
If @error > 0
BEGIN
ROLLBACK TRANSACTION
END
Else
BEGIN
COMMIT TRANSACTION
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
So
When I call the proc from Query Analyser, all rows get updated.
When I call the proc from within the program, only one row gets updated
Any ideas as to why this is happening??
JobID Description Price Status
----------------------------------------------
73412 Documents:Item 3 .00 0
73412 Documents:Item 5 .00 0
73412 Documents:Item 2 .00 0
73412 Documents:Item 4 .00 0
73412 Documents:Item 1 .00 0
^^^^Only one record gets updated, so the table ends up being...
JobID Description Price Status
----------------------------------------------
73412 Documents:Item 3 .00 4
73412 Documents:Item 5 .00 0
73412 Documents:Item 2 .00 0
73412 Documents:Item 4 .00 0
73412 Documents:Item 1 .00 0
Public Sub UpdateAllItems() As Boolean
Dim objCnn As ADODB.Connection
Dim objCmd As ADODB.Command
Set objCnn = New ADODB.Connection
With objCnn
.ConnectionString = cnConn
.CursorLocation = adUseClient
.Open
End With
Set objCmd = New ADODB.Command
Set objCmd.ActiveConnection = objCnn
With objCmd
.CommandText = "sp_UpdateJobItem"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@Status", adInteger, adParamInput, 4, Me.Status)
.Parameters.Append .CreateParameter("@JobID", adInteger, adParamInput, 4, Me.iJobID)
.Execute
End With
Set objCnn = Nothing
Set objCmd = Nothing
End Sub
-----------------------------------------------------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE dbo.sp_UpdateJobItem
@JobID As int
, @Status As int
AS
-- =============================================================================================
SET XACT_ABORT OFF -- Allow procedure to continue after error
DECLARE @error integer -- Local variable to capture the error OnHoldAction.
-- =============================================================================================
BEGIN TRANSACTION
UPDATE tbl_JobItems
SET Status = @status
WHERE JobID = @JobID
-- =============================================================================================
-- Check for errors
-- =============================================================================================
SELECT @error = @ERROR
If @error > 0
BEGIN
ROLLBACK TRANSACTION
END
Else
BEGIN
COMMIT TRANSACTION
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO