exam questions

Exam 70-487 All Questions

View all questions & answers for the 70-487 exam

Exam 70-487 topic 4 question 1 discussion

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

DRAG DROP -
You need to update the GetBook() method to retrieve book data by using ADO.NET.
You have the following code:

Which code segments should you include in Target 1, Target 2, Target 3, Target 4 and Target 5 to complete this code? (To answer, drag the appropriate code segments to the correct location in the answer area. Each segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:
Target 1: conn.Open();
Target 2: "SELECT id, name FROM books WHERE id =@id";
Example of how to use named parameters in CommandType.Text.
SELECT * FROM dbo.Customers WHERE CustomerID =@CustomerID
Target 3:cmd.Parameters.AddWithValue("@id", id);
Examples of AddWithValue usage:
cmdSQL.Parameters.AddWithValue("@CustomerID", CustomerID)
cmdSQL.Parameters.AddWithValue("@CartType", cartType)
Target 4: Id=readerGetGuid(Reader.GetOrdinal("id")),
Target 5: reader.GetString(Reader.GetOrdinal("name"))
Example of usage of GetOrdinal. Call GetOrdinal and assign value to variable. int customerID = reader.GetOrdinal("CustomerID");
References:
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.createcommand(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtext(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getordinal(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
Dev666
4 years, 8 months ago
for the @id =id would it actually matter which way around that was?
upvoted 1 times
Dreamchaser1980
4 years, 8 months ago
I think it matters because id is a column in the table which get the parameter value @id assigned to it. The @id parameter variable could be named any name for example @MyID as long as you configure the same name in the cmd.Parameters.Add, in contrast to this the id name must be named id because it references a column in the table.. // 2. define parameters used in command object SqlParameter param = new SqlParameter(); param.ParameterName = "@MyID"; param.Value = myVariable; // 3. add new parameter to command object cmd.Parameters.Add(param);
upvoted 2 times
...
zimzimzimma
4 years, 8 months ago
Yes, id is a column name and @id is a parameter variable declaration. Column must come before variables '@id = id' is an incorrect sql statement.
upvoted 3 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 ...