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?
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
A will not work, because the parameter isn’t specified in the query text.
.NET 4 link: http://msdn.microsoft.com/en-us/library/yy6y35y8(v=vs.100).aspx
Greetings! I’ve been following your weblog for a while now and finally got the bravery to go ahead and give you a shout
out from Houston Texas! Just wanted to mention keep up the fantastic job!