Web Resources

Answers to Self Review Exercises

20.1

a) SQL. b) rows, columns. c) primary key. d) DataSet. e) DataGridView. f) WHERE. g) ORDER BY. h) joining. i) foreign key. j) System.Data.SqlClient. k) System.Data. l) SqlCommand. m) BindingSource.

20.2

a) False. INSERT and DELETE statements also change the database. Do not confuse the SQL UPDATE statement with the Update method of a TableAdapter. b) False. Multiple rows can have the same value for a foreign key. Providing the same value for the primary key in multiple rows breaks the Rule of Entity Integritydoing so prevents each row from being identified uniquely. c) True. d) True. e) True. f) False. A DELETE statement deletes all rows satisfying the selection criteria in its WHERE clause. g) False. A BindingNavigator allows users to browse and manipulate data displayed by another GUI control. A TableAdapter can Fill a DataSet. h) True.

Exercises

20.3

(DisplayTable Application Modification) Modify the DisplayTable application in Section 20.6 to contain a TextBox and a Button that allow the user to search for specific authors by last name. Include a Label to identify the TextBox. Using the techniques presented in Section 20.8, add a query to the AuthorsTableAdapter that takes a parameter specifying the last name of the author to locate. When the user clicks the Button, the application should execute this query by passing the value entered in the TextBox to the appropriate Fill method of the AuthorsTableAdapter.

20.4

(DisplayQueryResult Application Modification) Modify the DisplayQueryResult application in Section 20.7 to contain a TextBox and a Button that allow the user to perform a search of the book titles in the Titles table of the Books database. Use a Label to identify the TextBox. When the user clicks the Button, the application should execute and display the result of a query that selects all the rows in which the search term entered by the user in the TextBox appears anywhere in the Title column. For example, if the user enters the search term "Visual," the DataGridView should display the rows for Visual Basic 2005 How to Program and Visual C# 2005 How to Program. If the user enters "Systems," the DataGridView should display only the row for Operating Systems. [Hint: Build a query that uses pattern matching with the % wildcard character. SQL supports string concatenation with the + operator, so you can combine '%' with a parameter by placing a + between them.]

20.5

(Baseball Database Application) Build an application that executes a query against the Players table of the Baseball database from Section 20.9. Display the table in a DataGridView, and add a TextBox and Button to allow the user to search for a specific player by last name. Use a Label to identify the TextBox. Clicking the Button should execute the appropriate query.

20.6

(Baseball Database Application Modification) Modify Exercise 20.5 to allow the user to locate players with batting averages in a specific range. Add a TextBoxtxtMinimum for the minimum batting average (0.000 by default) and a TextBoxtxtMaximum for the maximum batting average (1.000 by default). Use a Label to identify the TextBox. Add a Button for executing a query that selects rows from the Players table in which the BattingAverage column is greater than or equal to the specified minimum value and less than or equal to the specified maximum value. [Hint: Use method Decimal.Parse to convert the values of txtMinimum and txtMaximum to Decimal values before passing them to the appropriate Fill method of the PlayersTableAdapter.]

ASP NET 2 0, Web Forms and Web Controls

Категории