PrepAway - Latest Free Exam Questions & Answers

Which code segment should you add?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET. The application connects to a Microsoft SQL Server 2005 database.

The database contains a table named Categories. The Categories table has a primary key identity column named CategoryID.
The application inserts new records by using the following stored procedure.

CREATE PROCEDURE dbo.InsertCategory
@CategoryName nvarchar(15),
@Identity int OUT

AS
INSERT INTO Categories (CategoryName) VALUES(@CategoryName)
SET @Identity = SCOPE_IDENTITY()
RETURN @@ROWCOUNT

You write the following code segment.

SqlDataAdapter adapter = new SqlDataAdapter("SELECT categoryID, CategoryName FROM dbo.Categories",connection);
adapter.InsertCommand = new SqlCommand("dbo.InsertCategory", connection);
adapter.InsertCommand.CommandType = commandType.StoredProcedure;
adapter.InsertCommand.Parameters.Add(new SqlParameter("@CategoryName", SqlDbType.NVarChar, 15,"CategoryName"));

You need to retrieve the identity value for the newly created record.

Which code segment should you add?

PrepAway - Latest Free Exam Questions & Answers

A.
SqlParameter parameter = adapter.InsertCommand.Parameters.Add( "@CategoryID", SqlDbType.Int, 0);
parameter.Direction = ParameterDirection.Output;

B.
SqlParameter parameter = adapter.InsertCommand.Parameters.Add( "CategoryID", SqlDbType.Int, 0);
parameter.Direction = ParameterDirection.Output;

C.
SqlParameter parameter = adapter.InsertCommand.Parameters.Add( "@Identity", SqlDbType.Int, 0);
parameter.Direction = ParameterDirection.ReturnValue;

D.
SqlParameter parameter = adapter.InsertCommand.Parameters.Add( "@Identity", SqlDbType.Int, 0);
parameter.Direction = ParameterDirection.Output;


Leave a Reply