PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You use Microsoft .NET Framework 4 to develop an application that connects to a Microsoft SQL Server 2008 database.
You add the following stored procedure to the database.

CREATE PROCEDURE [dbo].[InsertTag]
@Name nvarchar (15)
AS
INSERT INTO [dbo].[Tags] (Name) VALUES(@Name)
RETURN @@ROWCOUNT

You need to invoke the stored procedure by using an open SqlConnection named conn.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
SqlCommand cmd = new SqlCommand(“EXEC InsertTag”, conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue(“@Name”, “New Tag 1”);
cmd.ExecuteNonQuery();

B.
SqlCommand cmd = new SqlCommand(“EXEC InsertTag”, conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(“@Name”, “New Tag 1”);
cmd.ExecuteNonQuery();

C.
SqlCommand cmd = new SqlCommand(“InsertTag”, conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue(“@Name”, “New Tag 1”);
cmd.ExecuteNonQuery();

D.
SqlCommand cmd = new SqlCommand(“InsertTag”, conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(“@Name”, “New Tag 1”);
cmd.ExecuteNonQuery();

Explanation:
http://msdn.microsoft.com/en-us/library/yy6y35y8(v=vs.71).aspx

3 Comments on “Which code segment should you use?


Leave a Reply