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.Connectio n
Dim objCmd As ADODB.Command
Set objCnn = New ADODB.Connectio n
With objCnn
.ConnectionStri ng = cnConn
.CursorLocation = adUseClient
.Open
End With
Set objCmd = New ADODB.Command
Set objCmd.ActiveCo nnection = objCnn
With objCmd
.CommandText = "sp_UpdateJobIt em"
.CommandType = adCmdStoredProc
.Parameters.App end .CreateParamete r("@Status", adInteger,
adParamInput, 4, Me.Status)
.Parameters.App end .CreateParamete r("@JobID", adInteger,
adParamInput, 4, Me.iJobID)
.Execute
End With
Set objCnn = Nothing
Set objCmd = Nothing
End Sub
-----------------------------------------------------------------
SET QUOTED_IDENTIFI ER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE dbo.sp_UpdateJo bItem
@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_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO
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.Connectio n
Dim objCmd As ADODB.Command
Set objCnn = New ADODB.Connectio n
With objCnn
.ConnectionStri ng = cnConn
.CursorLocation = adUseClient
.Open
End With
Set objCmd = New ADODB.Command
Set objCmd.ActiveCo nnection = objCnn
With objCmd
.CommandText = "sp_UpdateJobIt em"
.CommandType = adCmdStoredProc
.Parameters.App end .CreateParamete r("@Status", adInteger,
adParamInput, 4, Me.Status)
.Parameters.App end .CreateParamete r("@JobID", adInteger,
adParamInput, 4, Me.iJobID)
.Execute
End With
Set objCnn = Nothing
Set objCmd = Nothing
End Sub
-----------------------------------------------------------------
SET QUOTED_IDENTIFI ER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE dbo.sp_UpdateJo bItem
@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_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO
Comment