PrepAway - Latest Free Exam Questions & Answers

Which two actions should you perform?

You use Microsoft .NET Framework 4 to develop an application that connects to a Microsoft SQL
Server 2008 database. The database contains a ClassStudent table that contains the StudentID for
students who are enrolled in the classes.
You add the following stored procedure to the database.
CREATE PROCEDURE [dbo].[GetNumEnrolled]
@ClassID INT,
@NumEnrolled INT OUTPUT
AS
BEGIN
SET NOCOUNT ON
SELECT @NumEnrolled = COUNT(StudentID)
FROM ClassStudent
WHERE (ClassID = @ClassID)
END
You write the following code. (Line numbers are included for reference only.)
01 private int GetNumberEnrolled(string classID)
02 {
03 using (SqlConnection conn = new SqlConnection(GetConnectionString())

04 {
05 SqlCommand cmd = new SqlCommand(“GetNumEnrolled”, conn);
06 cmd.CommandType = CommandType.StoredProcedure;
07 SqlParameter parClass = cmd.Parameters.Add(“@ClassID”, SqlDbType.Int, 4,
“classID”);
08 SqlParameter parNum = cmd.Parameters.Add(“@NumEnrolled”, SqlDbType.Int);
09 …
10 conn.Open()
11 …
12 }
13 }
You need to ensure that the GetNumberEnrolled method returns the number of students who are
enrolled for a specific class.
Which two actions should you perform? (Each correct answer presents part of the solution. Choose
two.)

PrepAway - Latest Free Exam Questions & Answers

A.
Insert the following code at line 09.
parNum.Direction = ParameterDirection.Input;

B.
Insert the following code at line 09.
parNum.Direction = ParameterDirection.Output;

C.
Insert the following code at line 11.
int numEnrolled = 0;
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
numEnrolled = numEnrolled + (int)cmd.Parameters[“@NumEnrolled”].Value;
}
return numEnrolled;

D.
Insert the following code at line 11.
cmd.ExecuteNonQuery();
return (int)parNum.Value;


Leave a Reply