exam questions

Exam 70-487 All Questions

View all questions & answers for the 70-487 exam

Exam 70-487 topic 1 question 21 discussion

Actual exam question from Microsoft's 70-487
Question #: 21
Topic #: 1
[All 70-487 Questions]

You are developing an ASP.NET MVC application. The application has a page that searches for and displays an image stored in a database. Members of the
EntityClient namespace are used to access an ADO.NET Entity Framework data model Images and associated metadata are stored in a database table.
You need to run a query that returns only the image while minimizing the amount of data that is transmitted.
Which method of the EntityCommand type should you use?

  • A. ExecuteScalar
  • B. ExecuteDbDataReader
  • C. ExecuteReader
  • D. ExecuteNonQuery A
Show Suggested Answer Hide Answer
Suggested Answer: Explanation 🗳️
The SqlCommand.ExecuteScalar method executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
References:
https://msdn.microsoft.com/en-us/library/system.data.entityclient.entitycommand(v=vs.110).aspx

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
dalisaacs
Highly Voted 5 years, 5 months ago
correct answer is: A
upvoted 9 times
...
gokhan
Most Recent 4 years, 8 months ago
correct answer is: A, in here https://www.codeproject.com/Articles/10861/Storing-and-Retrieving-Images-from-SQL-Server-usin we can find an example
upvoted 1 times
...
gorundir
4 years, 9 months ago
ExecuteScalar may not be the right choice since the documentation says the return value "Returns a maximum of 2033 characters" which may not be sufficient for Blobs AND nowhere it is explicitly stated that the image is to be expected in the first column value. I'd go with a Reader which offers lightweight, forward-only data access.
upvoted 1 times
tanujgyan
4 years, 9 months ago
ExecuteScalar can return one column only and thats the only thing they need. ExecuteScalar should be correct
upvoted 2 times
mr_
4 years, 9 months ago
I have mixed feelings. On one hand ExecuteScalar sounds good because it returns single column from single row (so we can pass query like: 'SELECT img_blob FROM Images WHERE Id = 1'). In the requirements it is said that we want to load SINGLE image. But the problem is that ExecuteScalar has limitation of 2033 characters so for big blobs it may be not sufficient. ExecuteReader would solve that limitation issue I think but on the other hand it is not meant to read single row (even if it can be used like that without any problem), rather iterate through set of rows and loading only single row at a time. It is really fast though so I am not sure what is the correct answer. ExecuteNonQuery is wrong answer for sure. It is meant for commands, not queries (meaning not for SELECT statements).
upvoted 1 times
jan_oratowski
4 years, 4 months ago
As far as I remember, Microsoft recommends not using DB to store big files and use Blob Storage for that. So I think that 2033 chars limit isn't that important here. Also, since it says you're executing the query to get the image, you may be pretty sure that it's not going to be something like "SELECT * FROM Images" and will be more specific.
upvoted 1 times
...
...
...
...
mmk1991
5 years, 1 month ago
Answer A seems to be correct ExecuteScalar() only returns the value from the first column of the first row of your query. ExecuteReader() returns an object that can iterate over the entire result set. ExecuteNonQuery() does not return data at all: only the number of rows affected by an insert, update, or delete. http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery%28v=vs.110%29.aspx http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executereader%28v=vs.110%29.aspx http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar%28v=vs.110%29.aspx
upvoted 3 times
...
founderDev
5 years, 2 months ago
The SqlCommand.ExecuteScalar method executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago