S
ssp
Hi C#ers,
I have a stored proc. which is as follows. Supposedly returning the ID
(LocationID) of the row I've just inserted (scope identity):
=========================================
CREATE PROCEDURE [dbo].[LocationInsert]
@LocationName varchar(32),
@LocationDescription varchar(256),
@LocationID int OUTPUT,
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[Location] (
[LocationName],
[LocationDescription],
) VALUES (
@LocationName,
@LocationDescription,
)
SET @LocationID = Scope_Identity()
END
========================================
I then have the following code to insert the data from my code:
========================================
public void Insert(LocationEntity locationEntity)
{
DBCommandWrapper dbCommandWrapper =
this.Db.GetStoredProcCommandWrapper("LocationInsert");
dbCommandWrapper.AddInParameter("@LocationName", DbType.AnsiString,
locationEntity.Name);
dbCommandWrapper.AddInParameter("@LocationDescription",
DbType.AnsiString, locationEntity.Description.Value);
this.ExecuteSPNonQuery(dbCommandWrapper);
locationEntity.LocationID =
(int)dbCommandWrapper.GetParameterValue("@LocationID");
}
========================================
My question:
The Insert function is labeled "void". Will it return the ID
(LocationID) of the row I've just inserted? Infact, will the stored
procedure itself return the LocationID that I need?
SSP
I have a stored proc. which is as follows. Supposedly returning the ID
(LocationID) of the row I've just inserted (scope identity):
=========================================
CREATE PROCEDURE [dbo].[LocationInsert]
@LocationName varchar(32),
@LocationDescription varchar(256),
@LocationID int OUTPUT,
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[Location] (
[LocationName],
[LocationDescription],
) VALUES (
@LocationName,
@LocationDescription,
)
SET @LocationID = Scope_Identity()
END
========================================
I then have the following code to insert the data from my code:
========================================
public void Insert(LocationEntity locationEntity)
{
DBCommandWrapper dbCommandWrapper =
this.Db.GetStoredProcCommandWrapper("LocationInsert");
dbCommandWrapper.AddInParameter("@LocationName", DbType.AnsiString,
locationEntity.Name);
dbCommandWrapper.AddInParameter("@LocationDescription",
DbType.AnsiString, locationEntity.Description.Value);
this.ExecuteSPNonQuery(dbCommandWrapper);
locationEntity.LocationID =
(int)dbCommandWrapper.GetParameterValue("@LocationID");
}
========================================
My question:
The Insert function is labeled "void". Will it return the ID
(LocationID) of the row I've just inserted? Infact, will the stored
procedure itself return the LocationID that I need?
SSP