|
|
| Home >> Microsoft Certification >> MCSD >> Questions/Answers on Exam 070-305 >> QA7 |
Question:
You are creating an ASP.NET application which contains a page for retrieving Stock data from a Microsoft SQL server database. You are writing a method named GetStkInfo to run a stored procedure in the SQL server database. The stored procedure has one input parameter ‘StockID’, on the basis of StockID stored procedure returns the Stock Quantity for that particular stockID. You declare a numeric variable in the GetStkInfo method. You want to assign the value returned by the stored procedure to that variable, what should you do?
A. Create a SqlDataAdapter object and call its Fill method to run the stored procedure and assign the Stock Quantity value to your numeric variable.
B. Create a SqlDataAdapter object and call its Update method to run the stored procedure and assign the Stock Quantity value to your numeric variable.
C. Create a SqlCommand object and call its ExecuteScalar method to run the stored procedure and assigns Stock Quantity value to your numeric variable.
D. Create a SqlCommand object and call its ExecuteReader method to run the stored procedure and assign the Stock Quantity value to your numeric variable.
Correct Answer:
C
Explanation:
The SqlCommand.ExecuteScalar method executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored and only a single value is returned.
Incorrect Answers
A, B, D: All these commands return the collection of data. We only need a single result, not a collection of result set.
|
| Sponsored Links: |
|
|
| << back |
|
|
|