Data Access Application Block - Using UPDATEDATASET and Returning an Identity?

M

Mycroft

Hi,


I am tring to use the Microsoft Data Access Application Block v2 to
update the database. However, i need the stored procedure to return
the Identity value to the client application so it can know the ID of
the inserted record.

Example:
Stored Procedure:


CREATE PROC Person_Insert
@LASTNAME VARCHAR(30),
@FIRSTNAME VARCHAR(30),
@PersonID BIGINT OUTPUT
as
INSERT INTO PERSON (LASTNAME, FIRSTNAME)
VALUES (@LASTNAME, @FIRSTNAME)
SET @PersonID = (SELECT SCOPE_IDENTITY())


C# Code:

public void SavePerson(DataSet ds)
{
SqlConnection CurrentConnection = new SqlConnection connString);
CurrentConnection.Open();
SqlCommand insertCommand = SqlHelper.CreateCommand
CurrentConnection, "Person_Insert", "LASTNAME", "FIRSTNAME");
SqlCommand updateCommand =
SqlHelper.CreateCommand(CurrentConnection, "Person_Update",
"PersonID", "LASTNAME", "FIRSTNAME");
SqlCommand deleteCommand =
SqlHelper.CreateCommand(CurrentConnection, "Person_Delete",
"PersonID");
SqlParameter outParam = new SqlParameter();
outParam = updateCommand.Parameters.Add("@PersonID",SqlDbType.BigInt);
outParam.Direction = ParameterDirection.Output;
SqlHelper.UpdateDataset(insertCommand, deleteCommand,
updateCommand, ds, "table");
Console.WriteLine("UPDATE COMMAND OUTPUT PARAM:");
Console.WriteLine(outParam.Value.ToString());
}

Console Output:
UPDATE COMMAND OUTPUT PARAM:
The program '[2120] SmartClient.exe' has exited with code 0 (0x0).



This isn't working though. Any thoughts???

{Thanks in advance}
 
Top