Review Questions

1. 

How can you access the data in a DataTable if you do not explicitly assign a name to the DataTable when it is added to the DataSet by the Fill method?

  1. You cannot access the data unless you assign a name.

  2. You will receive a runtime error if you do not assign a name.

  3. You can reference the DataTable by using the DataSet.Tables collection, table index value.

  4. You can reference the DataTable by asking for the DataSet.DefaultTable.

cyou do not have to explicitly assign a table name. it will not cause an error. you can reference all the datatables in a dataset by iterating through the dataset.tables collection. defaulttable is not a valid property of the dataset.

2. 

Which statement best describes the structure of a DataSet?

  1. A DataSet contains a set of records returned from the database.

  2. A DataSet has a collection of DataTable objects. In turn, each DataTable has a collection of DataViews and DataRows.

  3. A DataSet has a collection of DataTable objects. In turn, each DataTable has a collection of DataColumns and DataRows.

  4. A DataSet contains collections of DataTables, DataColumns, and DataRows. Relationships between these objects are defined by DataRelations.

ca dataset contains a collection of datatables. the datatable in turn contains the datacolumns and datarows collections. the dataset, not the datatable, also contains the collection of dataviews, available through the dataviewmanager. the first option describes a recordset object from the older ado object model.

3. 

What will happen when you call the DataSet.AcceptChanges method?

  1. Changes that the user has made to the data in the DataSet will be sent to the database.

  2. The user will receive a message asking them to confirm their changes.

  3. Rows that the user changed in the DataSet will no longer have a row state of Modified. The original values will still be available.

  4. Rows that the user changed in the DataSet will no longer have a row state of Modified. The original values will no longer be available.

dthe acceptchanges method does not update the database or prompt the user. all changed, deleted, or inserted rows in the dataset will be marked as unchanged. the original values will be set to match the current values in the dataset-that is, the original values from the database will no longer be available locally in the dataset.

4. 

When you send a SQL Update instruction to the database with a DataAdapter.Update method call, how should you make sure that your statement will identify the correct record to update?

  1. Specify the original DataRow version of the primary key column in the WHERE clause of the SQL statement.

  2. Specify the current DataRow version of the primary key column in the WHERE clause of the SQL statement.

  3. Specify the default DataRow version of the primary key column in the WHERE clause of the SQL statement.

  4. Specify the proposed DataRow version of the primary key column in the WHERE clause of the SQL statement.

athe datarowversion.original setting will return the value that was originally retrieved from the database. specify this version in the sql where clause to ensure that you are updating the correct record in the database, even if the user inadvertently changed the primary key field.

5. 

You want to create custom error handling to determine when an update conflict has occurred at the database and to handle this appropriately. Which Catch block should you use?

  1. Catch ex As Exception

  2. Catch ex As DataException

  3. Catch ex as DBConcurrencyException

  4. Catch ex as DuplicateNameException

cthe dbconcurrencyexception is a specialized type of exception that will fire if dataadapter.update cannot send a change to the database because of a conflict. exception will catch any type of runtime error in your application. dataexception defines exceptions that are fired by ado.net objects. the duplicatenameexception would occur when filling a dataset, not during a database update.

6. 

What is a common use of a DataView?

  1. To send updates to the database.

  2. To pass data from one procedure to the next.

  3. To provide a sorted or filtered subset of the data in a DataTable.

  4. A DataView is a Windows forms control that displays data.

cthe dataview object is commonly used for its sort and filter properties that provide a customized view of the data, and its find method to locate specific items in a datatable. the dataadapter is responsible for sending updates to the database. the dataset is most appropriate for passing data from one procedure (or component) to another. the datagrid is a windows forms control that displays data.

7. 

You would like to use a DataView to create a subset of data that shows all rows that the user has deleted from a DataTable. Which property setting would you make?

  1. myView.RowFilter = DataViewRowState.Deleted

  2. myView.RowStateFilter = DataViewRowState.Deleted

  3. myView.RowFilter = "Deleted"

  4. myView.RowStateFilter = "Deleted"

buse the rowstatefilter property to filter rows based on the rowstate values, such as deleted , added , unchanged , and so on. use rowfilter to set a string to match data in a column.

8. 

You have created a ForeignKeyConstraint object in your DataSet. You want to allow the user to delete a row in the parent table and make sure that any child rows in a related table are also deleted. How can you accomplish this?

  1. Make sure the DeleteRule property of the constraint is set to Cascade.

  2. Make sure the DeleteRule property of the constraint is set to SetDefault.

  3. Make sure the RelatedColumns property of the constraint is set to Delete.

  4. Make sure the RelatedColumns property of the constraint is set to Cascade.

athe deleterule property controls what happens to child rows when a parent row is deleted. a setting of cascade will pass deletion of (or changes to) the parent row to the child rows. the relatedcolumns property gets a reference to the parent column of the constraint.

9. 

You want to create a UniqueConstraint for your DataTable to make sure that duplicate primary keys are not entered by the user. The primary key for the data you are working with is made up of two columns. How can you specify this when creating the constraint?

  1. Create two constraints, one for each column.

  2. Create a new column in the DataTable and combine both values into that column.

  3. Create references to both DataColumns and pass them as an array of DataColumn objects when creating the constraint.

  4. It is impossible to create a UniqueConstraint for multiple columns.

cthe uniqueconstraint constructor can accept a single column reference or an object array of multiple column references. creating two constraints would require uniqueness in each column, but would not act as a combined key. combining the values into a new column would not be effective.

10. 

A function in your application must create and return a new, empty DataSet object that has the same structure as the DataSet that is passed in. How can you accomplish this?

  1. Use the DataSet.Copy method.

  2. Use the DataSet.Merge method.

  3. Use the DataSet.Clear method.

  4. Use the DataSet.Clone method.

d dataset.clone creates a new dataset object that contains all of the same structural elements as the original but no data. copy creates a new dataset with all of the same structural elements, plus a copy of the original dataset s data. clear will remove all data from the original dataset. merge is used to combine two datasets.

11. 

You would like to use the Data Adapter Configuration Wizard to help you generate code for your application, but your database administrator allows access to data only through existing stored procedures. What should you do?

  1. Run the wizard in the standard fashion, and change the code manually to call stored procedures.

  2. Ask the database administrator to create appropriate stored procedures; you can then tell the wizard to generate code to call them.

  3. You will not be able to use the features of the wizard because the DataAdapter can call only stored procedures that it created.

  4. You will not be able to use the features of the wizard because the DataAdapter cannot call stored procedures.

bthe data adapter configuration wizard is flexible enough to generate sql statements in your source code, generate stored procedures, or create code that calls existing stored procedures. the first option would result in unnecessary work.

12. 

Your Windows application uses a DataSet object to allow users access to all of the data in your inventory table. Most users are interested in viewing information about only one category of inventory items at a time. How can you easily enable your users to restrict their viewing to a selected category?

  1. Provide a user interface element that enables a user to select from a list of categories. Then create a DataTable object that contains only rows that match the user’s selection.

  2. Provide a user interface element that enables a user to select from a list of categories. Then create a DataRow object that contains only rows that match the user’s selection.

  3. Provide a user interface element that enables a user to select from a list of categories. Then set the Filter property of the DataTable object to show only rows that match the user’s selection.

  4. Provide a user interface element that enables a user to select from a list of categories. Then set the Filter property of a DataView object to show only rows that match the user’s selection.

donly the dataview object provides a filter property. dataviews are the best way to filter, sort, or search data in a dataset.

13. 

You are creating an application that will be used by customer service representatives, working on your company’s local area network, to track service history and customer complaints. Your users will need to view customer history information, update the status of pending service calls, and input new service requests. What model would provide the most flexibility for your users?

  1. Use a DataSet to create a web page that displays customer information and link to other pages that enable the representative to input data.

  2. Use a DataReader to create a web page that displays customer information and link to other pages that enable the representative to input data.

  3. Create a DataSet that contains all pertinent customer information. The representative can review data, make changes, add new information, and submit updates after completing the call.

  4. Create a DataReader that contains all pertinent customer information. The representative can review data, make changes, add new information, and submit updates after completing the call.

c.in a local area network application or windows application, you can take advantage of client processing to maintain a local dataset with all necessary information. the dataset enables the user to scroll back and forth through data, and to edit and add new information. the datareader object provides a forward-only, read-only view of the data that is suitable for display on a web page or report.

14. 

You are using a DataAdapter to send changes to the database from your DataSet. Sometimes an error will occur at the database, and a row cannot be updated because of a conflict. You would like all other updates from the DataSet to complete. How can you ensure this behavior?

  1. Set a property of the DataSet that controls this behavior.

  2. Set a property of the DataAdapter that controls this behavior.

  3. If an error occurs, remove the row that has the error from the DataSet and try the update again.

  4. Call RejectChanges and try the update again.

bthe dataadapter object has a property called continueupdateonerror that controls this behavior. set this property to true , and updates for all rows that are not in error will go through. the property is false by default. the third option would be impractical, and the last option would remove all changes from the dataset, so that no updates would go through.

15. 

You have set the ContinueUpdateOnError property to True. All of your update operations seem to complete successfully, but some changes are not showing up in the database. How can you determine which rows failed to update?

  1. Iterate through the DataSet.GetErrors collection.

  2. Iterate through the collection created by the DataTable.GetErrors method.

  3. Iterate through the DataSet.HasErrors collection.

  4. Iterate through the collection created by the DataTable.HasErrors method.

bthe datatable has a geterrors method that returns a collection of datarow objects with a value in their rowerror property. the dataset does not have a geterrors method. the haserrors property is available for the dataset, datatable, and datarow objects, but it returns only a boolean value that indicates whether there are any errors at all for the object.

Answers

1. 

C You do not have to explicitly assign a table name. It will not cause an error. You can reference all the DataTables in a DataSet by iterating through the DataSet.Tables collection. DefaultTable is not a valid property of the DataSet.

2. 

C A DataSet contains a collection of DataTables. The DataTable in turn contains the DataColumns and DataRows collections. The DataSet, not the DataTable, also contains the collection of DataViews, available through the DataViewManager. The first option describes a RecordSet object from the older ADO object model.

3. 

D The AcceptChanges method does not update the database or prompt the user. All changed, deleted, or inserted rows in the DataSet will be marked as unchanged. The original values will be set to match the current values in the DataSet—that is, the original values from the database will no longer be available locally in the DataSet.

4. 

A The DataRowVersion.Original setting will return the value that was originally retrieved from the database. Specify this version in the SQL WHERE clause to ensure that you are updating the correct record in the database, even if the user inadvertently changed the primary key field.

5. 

C The DBConcurrencyException is a specialized type of exception that will fire if DataAdapter.Update cannot send a change to the database because of a conflict. Exception will catch any type of runtime error in your application. DataException defines exceptions that are fired by ADO.NET objects. The DuplicateNameException would occur when filling a DataSet, not during a database update.

6. 

C The DataView object is commonly used for its Sort and Filter properties that provide a customized view of the data, and its Find method to locate specific items in a DataTable. The DataAdapter is responsible for sending updates to the database. The DataSet is most appropriate for passing data from one procedure (or component) to another. The DataGrid is a Windows forms control that displays data.

7. 

B Use the RowStateFilter property to filter rows based on the RowState values, such as Deleted, Added, Unchanged, and so on. Use RowFilter to set a string to match data in a column.

8. 

A The DeleteRule property controls what happens to child rows when a parent row is deleted. A setting of Cascade will pass deletion of (or changes to) the parent row to the child rows. The RelatedColumns property gets a reference to the parent column of the constraint.

9. 

C The UniqueConstraint constructor can accept a single column reference or an object array of multiple column references. Creating two constraints would require uniqueness in each column, but would not act as a combined key. Combining the values into a new column would not be effective.

10. 

D DataSet.Clone creates a new DataSet object that contains all of the same structural elements as the original but no data. Copy creates a new DataSet with all of the same structural elements, plus a copy of the original DataSet’s data. Clear will remove all data from the original DataSet. Merge is used to combine two DataSets.

11. 

B The Data Adapter Configuration Wizard is flexible enough to generate SQL statements in your source code, generate stored procedures, or create code that calls existing stored procedures. The first option would result in unnecessary work.

12. 

D Only the DataView object provides a Filter property. DataViews are the best way to filter, sort, or search data in a DataSet.

13. 

C. In a local area network application or Windows application, you can take advantage of client processing to maintain a local DataSet with all necessary information. The DataSet enables the user to scroll back and forth through data, and to edit and add new information. The DataReader object provides a forward-only, read-only view of the data that is suitable for display on a web page or report.

14. 

B The DataAdapter object has a property called ContinueUpdateOnError that controls this behavior. Set this property to True, and updates for all rows that are not in error will go through. The property is False by default. The third option would be impractical, and the last option would remove all changes from the DataSet, so that no updates would go through.

15. 

B The DataTable has a GetErrors method that returns a collection of DataRow objects with a value in their RowError property. The DataSet does not have a GetErrors method. The HasErrors property is available for the DataSet, DataTable, and DataRow objects, but it returns only a Boolean value that indicates whether there are any errors at all for the object.



MCAD/MCSD(c) Visual Basic. NET XML Web Services and Server Components Study Guide
MCAD/MCSD: Visual Basic .NET XML Web Services and Server Components Study Guide
ISBN: 0782141935
EAN: 2147483647
Year: 2005
Pages: 153

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