Microsoft Exam Questions

Which code elements needs to be added in the empty lines?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
You create a stored procedure to insert a new record in the Categories table according to following code segment.

CREATE PROCEDURE dbo.InsertCategory
@CategoryName navrchar(15),
@Identity int OUT
AS
INSERT INTO Categories(CategoryName) VALUES (@CategoryName)
SET @Identity = SCOPE_IDENTITY()
RETURN @@ROWCOUNT

You add the following code fragment. (Line numbers are included for reference only.)

01 private static void ReturnIdentity(string connectionString)
02 {
03 using(SqlConnection connection = new SqlConnection(connectionString))
04 {
05 SqlDataAdpater adapter = new SqlDataAdapter(“SELECT CategoryID, CategoryName FROM dbo.Categories”, connection);
06 adapter.InsertCommand = new SqlCommand(“InsertCategory”, connection);
07 adapter.InsertCommand.CommandType = CommandType.StoredProcedure;
08 SqlParameter rowcountParameter = adapter.InsertCommand.Parameters.Add(“@RowCount”, SqlDbType.Int);
09 …
10 adapter.InsertCommand.Parameters.Add(“@CategoryName”, SqlDbType.NChar, 15, “CategoryName”);
11 SqlParameter identityParameter = adapter.InsertCommand.Parameters.Add(“@Identity”, SqlDbType.Int, 0, “CategoryID”);
12 …
13 DataTable categories = new DataTable();
14 adapter.Fill(categories);
15 DataRow ctegoryRow = categories.NewRow();
16 categoryRow[“CategoryName”] = “New beverages”;
17 categories.Rows.Add(categoryRow);
18 adapter.Update(categories);
19 Int32 rowCount = (Int32)adapter.InsertCommand.Parameters[“@RowCount”].Value;
20 }
21 }

Which code elements needs to be added in the empty lines?

A.
Insert the following code segment at line 09:
rowcountParameter.Direction = ParameterDirection.ReturnValue;
Insert the following code segment at line 12:
identityParameter.Direction = ParameterDirection.ReturnValue;

B.
Insert the following code segment at line 09:
rowcountParameter.Direction = ParameterDirection.Output;
Insert the following code segment at line 12:
identityParameter.Direction = ParameterDirection.Output;

C.
Insert the following code segment at line 09:
rowcountParameter.Direction = ParameterDirection.ReturnValue;
Insert the following code segment at line 12:
identityParameter.Direction = ParameterDirection.Output;

D.
Insert the following code segment at line 09:
rowcountParameter.Direction = ParameterDirection.Output;
Insert the following code segment at line 12:
identityParameter.Direction = ParameterDirection.ReturnValue;

Explanation:
Input – The parameter is an input parameter.
InputOutput – The parameter is capable of both input and output.
Output – The parameter is an output parameter.
ReturnValue – The parameter represents a return value from an operation such as a stored procedure, built-in function, or user-defined function.

ParameterDirection Enumeration
(http://msdn.microsoft.com/en-us/library/system.data.parameterdirection(v=vs.71).aspx)