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 GNumEnrolled = COUNT(StudentID)
FROM ClassStudent
WHERE (ClassID = @ClassID)
END
You write the following code. (Line numbers are included for reference only.)
01 Private Function GetNumberEnrolled(
ByVal classID As String) As Integer 02
03 Using conn As New SqlConnection(GetConnectionString())
04
05 Dim cmd As SqlCommand = New SqlCommand(
“GetNumEnro1led”, conn)
06 cmd.CommandType = CommandType.StoredProcedure
07 Dim parClass As SqlParameter – cmd.Parameters.Add(
“8ClassID”, SqlDbType.Int, 4, classID)
08 Dim parNum As SqlParameter = cmd.Parameters.Add(
“@NumEnrolled”, SqlDbType.Int)
09
10 conn.Open()
11
12 End Using
11 End Function
You need to ensure that the GetlMumberEnrolled 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.
Dim numEnrolled As Integer = 0
Dim reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read()
numEnrolled = numEnrolled +
DirectCast(cmd.Parameters(“@NumEnrolled”).Value_
Integer)
End
While Return numEnrolled

D.
Insert the following code at line 11.
cmd.ExecuteNonQuery()
Return DirectCast (parNum.Value, Integer)

Explanation:


Leave a Reply