J
Jason James
Hi all,
I have written stored procdures to manager inserts,
updates and deletes of my data. These procedures
are supplied to the data adapter that is being tasked
with updating data from my dataset.
However, to address some of the table relationship issues
I want to be able to retrieve the ID of the last inserted
record using SCOPE_IDENTITY.
Can I modify the SP to return SCOPE_IDENTITY
as a parameter of the command and then use the
parameter value to update the corresponding value
in the datarow that has just been inserted using
something like this:
Private Sub sqlDa_RowUpdated(ByVal sender As Object, ByVal e As
SqlRowUpdatedEventArgs)
If e.StatementType = StatementType.Insert Then
Dim x As Int32
x = sqlInsertCmd.Parameters("iID").Value
e.Row("iID") = x
e.AcceptChanges()
End If
End Sub
Where Paramters("iID") contains the SCOPE_IDENTITY
value from the SP.
My SP looks like this a the moment:
ALTER PROC imInsertItems
@ilID INT,
@iPartNumber NVARCHAR(50),
@iDescription NVARCHAR(50),
@iUnits INT,
@iQty INT,
@iGRNNum INT,
@iGRNType NVARCHAR(50),
@iTime datetime,
@iGroup NVARCHAR(50),
@iUserName NVARCHAR(50),
@iID INT OUTPUT
AS
INSERT INTO tblStockTake_Items
(ilID, iPartNumber, iDescription, iUnits, iQty, iGRNNum, iGRNType,
iTime, iGroup, iUserName)
VALUES
(@ilID, @iPartNumber, @iDescription, @iUnits, @iQty, @iGRNNum,
@iGRNType, @iTime, @iGroup, @iUserName)
SET @iID = SCOPE_IDENTITY
Is this a trival problem or so I have to query the database
using a datareader and obtain SCOPE_IDENTITY using
execute scaler?
Many thanks,
Jason.
I have written stored procdures to manager inserts,
updates and deletes of my data. These procedures
are supplied to the data adapter that is being tasked
with updating data from my dataset.
However, to address some of the table relationship issues
I want to be able to retrieve the ID of the last inserted
record using SCOPE_IDENTITY.
Can I modify the SP to return SCOPE_IDENTITY
as a parameter of the command and then use the
parameter value to update the corresponding value
in the datarow that has just been inserted using
something like this:
Private Sub sqlDa_RowUpdated(ByVal sender As Object, ByVal e As
SqlRowUpdatedEventArgs)
If e.StatementType = StatementType.Insert Then
Dim x As Int32
x = sqlInsertCmd.Parameters("iID").Value
e.Row("iID") = x
e.AcceptChanges()
End If
End Sub
Where Paramters("iID") contains the SCOPE_IDENTITY
value from the SP.
My SP looks like this a the moment:
ALTER PROC imInsertItems
@ilID INT,
@iPartNumber NVARCHAR(50),
@iDescription NVARCHAR(50),
@iUnits INT,
@iQty INT,
@iGRNNum INT,
@iGRNType NVARCHAR(50),
@iTime datetime,
@iGroup NVARCHAR(50),
@iUserName NVARCHAR(50),
@iID INT OUTPUT
AS
INSERT INTO tblStockTake_Items
(ilID, iPartNumber, iDescription, iUnits, iQty, iGRNNum, iGRNType,
iTime, iGroup, iUserName)
VALUES
(@ilID, @iPartNumber, @iDescription, @iUnits, @iQty, @iGRNNum,
@iGRNType, @iTime, @iGroup, @iUserName)
SET @iID = SCOPE_IDENTITY
Is this a trival problem or so I have to query the database
using a datareader and obtain SCOPE_IDENTITY using
execute scaler?
Many thanks,
Jason.