Exam Prep Questions

Team-Fly    

Developing XML Web Services and Server Components with Visual C#™ .NET and the .NET Framework, Exam Cram™ 2 (Exam 70-320)
By Amit Kalani, Priti Kalani

Table of Contents
Chapter 2.  Consuming and Manipulating DataSets


Question 1

You are developing an XML schema file for an application that will retrieve data from an Oracle database. The database includes an Orders table and a LineItems table. Each order has one or more line items associated with it. You've already created the Orders table within the XML schema file. How should you represent the LineItems table within the XML schema file?

  • A. Add LineItems as a separate table. Use a one-to-many relationship to relate the LineItems table to the Orders table.

  • B. Add LineItems as a separate table. Use a nested relationship to relate the LineItems table to the Orders table.

  • C. Add LineItems as a simple type. Add a row using this simple type to the Orders table.

  • D. Add LineItems as an element. Add a row using this element to the Orders table.

A1:

The correct answer is A. For data stored in a relational database, one-to-many relationships provide the most natural mapping in an XML schema file. Answer B is incorrect because nested relationships generally provide the most natural mapping for data coming from XML sources. Answer C is incorrect because simple type is not useful for storing structured data types such as LineItems. Answer D is incorrect because LineItems is a table and cannot be used as an element.

Question 2

Your application includes a strongly typed DataSet object named dsWarehouse. You have extracted a table named Inventory from the DataSet object to a DataTable object named dtInventory. The Inventory table contains a column named StockOnHand. Which syntax can you use to refer to a value in this column? (Select two.)

  • A. dtInventory.Rows[0].StockOnHand

  • B. dtInventory.Rows[0]."StockOnHand"

  • C. dtInventory.Rows[0]["StockOnHand"]

  • D. dtInventory.Rows[0].Item.StockOnHand

A2:

The correct answers are A and C. The early bound syntax of answer A is possible only with a strongly typed DataSet object. But you're not required to use early binding with strongly typed DataSet objects, so the late-bound syntax of answer C also works. Answer B is incorrect because the column name should not be included in quotes. Answer D is incorrect because the Item property of a DataRow object requires the use of a column index rather than column name.

Question 3

You are developing an XML schema file for an application that will retrieve data from Web applications developed by your company's trading partners. These Web applications use XML as their native format. The information you will retrieve includes a list of parts and a list of prices. Each part has one or more prices associated with it. You've already created the Parts table within the XML schema file. How should you represent the Prices table within the XML schema file?

  • A. Add Prices as a separate table. Use a one-to-many relationship to relate the Prices table to the Parts table.

  • B. Add Prices as a separate table. Use a nested relationship to relate the Prices table to the Parts table.

  • C. Add Prices as a simple type. Add a row using this simple type to the Parts table.

  • D. Add Prices as an element. Add a row using this element to the Parts table.

A3:

The correct answer is B. For data coming from XML sources, nested relationships generally provide the most natural mapping in an XML schema file. Answer A is incorrect because one-to-many relationships provide the most natural mapping for the data stored in a relational database. Answer C is incorrect because the simple type is not useful for storing structured data types such as Prices. Answer D is incorrect because there can be one or more prices associated with each part and, therefore, Prices cannot be used as an element.

Question 4

You are developing an XML schema file that will hold information about your company's customers. Which of these data restrictions can you represent by a facet in the schema?

  • A. The values of the CustomerType element are limited to "Active" and "Inactive".

  • B. The values of the CustomerID element must be four characters long for active customers and five characters long for inactive customers.

  • C. Each customer can have one or more representatives.

  • D. Each customer is associated with precisely one company.

A4:

The correct answer is A. You can represent a fixed set of choices within a simple type by using the enumeration facet. Answer B is incorrect because you cannot represent conditional values by using the facets. Answer C is incorrect because facets are not suited for representing relationships between elements within a table. Answer D is incorrect because facets are not suitable for representing relationships between different tables.

Question 5

Your application needs to return the total number of customers in the database. What is the fastest way to do this?

  • A. Write ad hoc SQL to return the total number of customers. Use the SqlCommand.ExecuteScalar() method to execute the SQL statement.

  • B. Write ad hoc SQL to return the total number of customers. Use the SqlDataAdapter.Fill() method to execute the SQL statement.

  • C. Create a stored procedure to return the total number of customers. Use the SqlCommand.ExecuteScalar() method to execute the stored procedure.

  • D. Create a stored procedure to return the total number of customers. Use the SqlDataAdapter.Fill() method to execute the stored procedure.

A5:

The correct answer is C. Stored procedures execute faster than the corresponding ad hoc SQL statements because stored procedures are stored in the database in compiled form. The ExecuteScalar() method is faster than filling a DataSet object for returning a single value. Answer A is incorrect because the ad hoc SQL statements run slower than stored procedures. Answers B and D are incorrect because the use of the SqlDataAdapter.Fill() method has significantly higher performance overhead than the SqlCommand.ExecuteScalar() method when a query or stored procedure returns a single value.

Question 6

Your application needs to retrieve a list of customer balances from a SQL Server database. The application should move through the list once, processing each balance in turn. The application does not need to write to the database. Your solution should process the data as quickly as possible. Which object should you use to hold the list in the data model?

  • A. DataSet

  • B. SqlDataReader

  • C. DataTable

  • D. DataView

A6:

The correct answer is B. The SqlDataReader object gives you a fast, forward-only, read-only view of the data. Answers A, C, and D are incorrect because these objects have significant overhead when compared to SqlDataReader.

Question 7

Your application uses a SqlDataReader object to retrieve information about customer balances. When you find a past-due balance, you want to write a new entry to a billing table by executing a stored procedure in the same database. You have used a SqlCommand object to represent the stored procedure. Calling the ExecuteNonQuery() method of the SqlCommand object is causing an error. What is the most likely cause of this error?

  • A. You must use a SqlDataAdapter object to execute the stored procedure.

  • B. You must use an ad hoc SQL statement rather than a stored procedure to insert new rows in a database.

  • C. You are using the ExecuteNonQuery() method of the SqlCommand object, and you should be using the ExecuteScalar() method instead.

  • D. You are using the same SqlConnection object for both the SqlDataReader object and the SqlCommand object, and the SqlDataReader object is still open when you try to execute the SqlCommand object.

A7:

The correct answer is D. While a SqlDataReader object is open, you cannot execute other commands on the SqlConnection object that the SqlDataReader object is using. Answer A is incorrect because the SqlCommand object can be used to execute the stored procedure. Answer B is incorrect because stored procedures can be used to insert new rows in a database. Answer C is incorrect because the ExecuteScalar() method is used to return just a single value; however, the insert operation does not return any rows, so using the ExecuteNonQuery() method is correct.

Question 8

Your application enables the user to edit product data on a DataGrid control, which is bound to a DataSet object. The DataSet object is filled through a SqlDataAdapter object. The InsertCommand, UpdateCommand, and DeleteCommand properties of the SqlDataAdapter object are set to SqlCommand objects, and you have tested the SQL in those SqlCommand objects.

When users submit the page, none of their changes are saved to the database, and they do not receive any errors. What could be the problem?

  • A. You have neglected to call the SqlDataAdapter.Update() method in your code.

  • B. The users do not have permission to write to the database.

  • C. You have neglected to fill the DataSet object from the DataGrid control after the users finish editing the data.

  • D. The DataSet object is a read-only object.

A8:

The correct answer is A. If you do not call the SqlDataAdapter.Update() method, all changes to the data model are lost. Answer B is incorrect because it returns an error to the users. Answer C is incorrect because a bound DataSet object automatically reflects changes to the DataGrid control. Answer D is incorrect because DataSet objects are designed to be edited.

Question 9

You enable users to edit product information on a DataGrid control bound to a DataSet object. When a user clicks the Update button on the form, you call the SqlDataAdapter.Update() method to cause the changes from the DataSet object to persist to the underlying database.

Users report that new records and updated rows are saved properly but that deleted rows are reappearing the next time they run the application. What could be the problem?

  • A. The users do not have permission to update the underlying table.

  • B. The Update() method does not delete rows.

  • C. Someone is restoring an old version of the database between the two executions of the program.

  • D. The DeleteCommand property of the SqlDataAdapter object points to a SqlCommand object that does not properly delete rows.

A9:

The correct answer is D. Answers A and C are incorrect because, if this would have been the case, none of the changes would have been saved. Answer B is incorrect because the Update() method can delete rows from the data source if the corresponding row has been deleted from the DataSet object.

Question 10

Your application includes a DataSet object that contains a DataTable object named Suppliers. This DataTable object contains all rows from the Suppliers table in your database. You want to bind an object to a DataGrid control on a form so that the DataGrid control displays only the Suppliers from Pennsylvania. What should you do?

  • A. Create a filtered array by calling the DataTable.Select() method on the Suppliers DataTable object, and bind the array to the DataGrid control.

  • B. Create a new SqlCommand object to retrieve only suppliers from Pennsylvania. Use a new SqlDataAdapter object to fill a new DataSet object with these suppliers. Bind the new DataSet object to the DataGrid control.

  • C. Use a foreach loop to move through the entire Suppliers DataTable object. Each time you find a DataRow object representing a supplier from Pennsylvania, bind that DataRow object to the DataGrid control.

  • D. Create a filtered DataView object from the Suppliers DataTable object and bind the DataView object to the DataGrid control.

A10:

Answer D is correct. Answers A and C are incorrect because these answers do not give you objects that can be bound to the DataGrid control. Answer B is incorrect because retrieving the data from the database a second time will be slower than filtering it from the existing DataTable object.


    Team-Fly    
    Top


    MCAD Developing XML Web Services and Server Components with Visual C#. NET and the. NET Framework Exam Cram 2 (Exam Cram 70-320)
    Managing Globally with Information Technology
    ISBN: 789728974
    EAN: 2147483647
    Year: 2002
    Pages: 179

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net