You develop an inventory management application called XYZManagement that will call aMicrosoft SQL Server stored procedure named sp_GetDailyXYZSales. The stored procedure will run a query that returns your daily sales total as an output parameter.This total will be displayed to users in a message box.
Your application uses a SqlCommand object to run sp_GetDailyXYZSales. You write the
following code to call sp_GetDailyXYZSales:
SqlConnection cnn = new SqlConnection(myConnString);
SqlCommand cmd = new SqlCommand(“sp_GetDaily XYZ Sales”, cnn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm = cmd.Parameters.Add(“@ItemTotal”,SqlDbType.Int);
prm.Direction = ParameterDirection.Output;
cnn.Open();
cmd.ExecuteNonQuery();
Now you must write additional code to access the output parameter. Which code segment should you use?

You develop an inventory management application called XYZManagement that will call aMicrosoft SQL Server stored procedure named sp_GetDailyXYZSales. The stored procedure will run a query that returns your daily sales total as an output parameter.This total will be displayed to users in a message box.
Your application uses a SqlCommand object to run sp_GetDailyXYZSales. You write the
following code to call sp_GetDailyXYZSales:
SqlConnection cnn = new SqlConnection(myConnString);
SqlCommand cmd = new SqlCommand(“sp_GetDaily XYZ Sales”, cnn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm = cmd.Parameters.Add(“@ItemTotal”,SqlDbType.Int);
prm.Direction = ParameterDirection.Output;
cnn.Open();
cmd.ExecuteNonQuery();
Now you must write additional code to access the output parameter. Which code segment should you use? Correct Answer

The @ItemTotal parameter is declared as an output parameter with SQL Server data type INT.We use the Value property of the SQLParameter class to retrieve the value of this parameter. We must also convert the INT value to a string value with the ToString method. We then supply this string to the MessageBox.Show method. 

 

Incorrect Answers

Option A, B:The @ItemTotal parameter is the output parameter. Using @Output this way is incorrect. Output is a keyword and no variable named @Output has been declared.

Option D:We must use the Value method to retrieve the value of the parameter..

Related Questions

Your network consists of a single Active Directory domain. The domain includes a group named SalesUsers. You have a file server that runs Windows Server 2003 Service Pack 2 (SP2). The server has a folder named CorpData. You share the CorpData folder and assign the Domain Users group the Full Control share permission. In the CorpData folder, you create a folder named Sales. You need to configure security for the Sales folder to meet the following requirements: -Members of the SalesUsers group must be able to read, create, and modify all files and folders. -All other users must be able to view items in the folder. What should you do?