nerdexam
Microsoft

70-516 · Question #58

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…

The correct answer is C. Insert the following code segment at line 09. See the full explanation below for the reasoning.

Question

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?

Options

  • AInsert the following code segment at line 09:
  • BInsert the following code segment at line 09:
  • CInsert the following code segment at line 09:
  • DInsert the following code segment at line 09:

How the community answered

(26 responses)
  • A
    4% (1)
  • B
    12% (3)
  • C
    81% (21)
  • D
    4% (1)

Community Discussion

No community discussion yet for this question.

Full 70-516 Practice