chapter 11

advertisement
Programming Right From the Start with Visual Basic.NET
CHAPTER 11
Databases and ADO.NET
True-False Questions
1.
2.
3.
A record in a database can contain multiple fields.
Answer: True
Section: 11-1
Level: Easy
Page: 287
A field in a database can contain multiple tables.
Answer: False
Section: 11-1
Level: Easy
Page: 287
A table in a database can contain multiple records.
Answer: True
Section: 11-1
Level: Easy
Page: 287
4.
A relational database model specifies the relationship between records.
Answer: False
Level: Moderate
Section: 11-1
Page: 287
5.
The foreign key in a table uniquely identifies each row.
Answer: False
Level: Moderate
Section: 11-1
Page: 287
6.
The primary and foreign keys identify the relationship between tables.
Answer: True
Level: Moderate
Section: 11-1
Page: 287
7.
One example of a relationship between tables is the one to many relationship.
Answer: True
Level: Moderate
Section: 11-1
Page: 289
8.
The primary and foreign keys are the only fields in most tables.
Answer: False
Level: Moderate
Section: 11-1
Page: 287
9.
Microsoft Access is the only program available to create a database.
Answer: False
Level: Easy
Section: 11-1
Page: 288
10.
The normalization process is used to eliminate data redundancy.
Answer: True
Level: Easy
Section: 11-1
Page: 289
11 - 1
Chapter 11 – Databases and ADO.NET
11.
Information is retrieved from the database using the Structured Query Language.
Answer: True
Level: Easy
Section: 11-2
Page: 290
12.
The SELECT clause of an SQL query specifies which fields are retrieved.
Answer: True
Level: Easy
Section: 11-2
Page: 290
13.
The FROM clause of an SQL query specifies which rows are retrieved.
Answer: False
Level: Easy
Section: 11-2
Page: 290
14.
The # symbol in an SQL query is a wildcard, which retrieves all fields in a table.
Answer: False
Level: Easy
Section: 11-2
Page: 290
15.
Square brackets [ ] must surround any database field name that has a space in it.
Answer: True
Level: Moderate
Section: 11-2
Page: 290
16.
The WHERE clause must have criteria for restricting a subset of the data.
Answer: True
Level: Easy
Section: 11-2
Page: 291
17.
The four relational operators allowed in the WHERE clause are >, <, =, and <>.
Answer: False
Level: Easy
Section: 11-2
Page: 291
18.
The WHERE clause is not often used in the daily retrieval of information from a database.
Answer: False
Level: Moderate
Section: 11-2
Page: 291
19.
The default for the ORDER BY clause of an SQL query is descending.
Answer: False
Level: Easy
Section: 11-2
Page: 292
20.
The ORDER BY clause in optional is an SQL query.
Answer: True
Section: 11-2
Level: Moderate
Page: 291
21.
The JOIN clause of an SQL query is used to get related data from two tables.
Answer: True
Level: Easy
Section: 11-2
Page: 292
22.
The default for a JOIN clause is the INNER JOIN type.
Answer: True
Level: Moderate
Section: 11-2
Page: 293
11 - 2
Chapter 11 – Databases and ADO.NET
23.
The DBMS will automatically determine the primary and foreign key fields to use in a JOIN
statement.
Answer: False
Level: Hard
Section: 11-2
Page: 293
24.
ADO.NET uses three objects to access a database: Command, DataAdapter, and Dataset.
Answer: False
Level: Moderate
Section: 11-3
Page: 294
25.
The OleDbConnection ADO.NET object is used to create a connection to an Access database.
Answer: True
Level: Easy
Section: 11-3
Page: 294
26.
An OleDbConnection ADO.NET object added from the Toolbox is displayed on the Form.
Answer: False
Level: Easy
Section: 11-3
Page: 295
27.
The ConnectionString property of the OleDbConnection object must be set before your VB.NET
program can access a database.
Answer: True
Level: Moderate
Section: 11-3
Page: 295
28.
The DataAdapter object can be created prior to the OleDbConnection object.
Answer: False
Level: Moderate
Section: 11-3
Page: 297
29.
The DataAdapter object acts as translator between the VB.NET program and the database.
Answer: True
Level: Easy
Section: 11-3
Page: 297
30.
The SQL query sent to the database can be typed in or created graphically.
Answer: True
Level: Moderate
Section: 11-3
Page: 299
31.
A Configuration Wizard can be used to help the developer configure the DataAdapter Object.
Answer: True
Level: Easy
Section: 11-3
Page: 298
32.
The Dataset is created after the creation of the DataAdapter.
Answer: True
Level: Easy
Section: 11-3
Page: 300
33.
Only the Dataset object shows up in the component tray.
Answer: False
Level: Easy
Section: 11-3
Page: 301
34.
A Dataset is a reference to the database and the data is not actually stored on the local computer.
Answer: False
Level: Moderate
Section: 11-3
Page: 300
11 - 3
Chapter 11 – Databases and ADO.NET
35.
The information in a Dataset can automatically be displayed if a data-aware control is bound to it.
Answer: True
Level: Easy
Section: 11-4
Page: 302
36.
The DataBinding property of a data-aware control identifies the field to be displayed.
Answer: False
Level: Moderate
Section: 11-4
Page: 302
37.
The data-aware control gets the field to display from the DataAdapter Object.
Answer: False
Level: Easy
Section: 11-4
Page: 302
38.
The fill method must be placed in the Form Load event.
Answer: False
Level: Easy
Section: 11-4
Page: 303
39.
The Clear method of a Dataset should be called before using the Fill method of a DataAdapter.
Answer: True
Level: Moderate
Section: 11-4
Page: 303
40.
The count property is one more than the position of the last record.
Answer: True
Level: Moderate
Section: 11-4
Page: 303
41.
The BindingContext position property can be read while the program is running but it cannot be
changed with an assignment statement.
Answer: False
Level: Moderate
Section: 11-4
Page: 303
42.
To display ADO.NET data in a DataGrid you must set the DataGrid properties at design time.
Answer: False
Level: Moderate
Section: 11-5
Page: 305
43.
The DataMember property of a DataGrid contains the name of the Dataset object.
Answer: False
Level: Moderate
Section: 11-5
Page: 305
44.
Both the DataMember and DataSource properties need to be specified for the DataGrid to work.
Answer: True
Level: Moderate
Section: 11-5
Page: 305
45.
One form can contain multiple DataAdapters, which use the same Connection object.
Answer: True
Level: Moderate
Section: 11-5
Page: 305
11 - 4
Chapter 11 – Databases and ADO.NET
Multiple Choice Questions
46.
Where is a single element of data stored?
a.) Field
b.) Record
c.) Table
d.) Both a and b.
e.) All of the above.
Answer: a
Section: 11-1
47.
Level: Easy
Page: 287
Where is a collection of related data elements stored?
a.) Field
b.) Record
c.) Table
d.) Both a and b.
e.) All of the above.
Answer: b
Section: 11-1
48.
Level: Easy
Page: 287
Which is true about the primary key?
a.) Every table should have a primary key.
b.) A primary key exclusively identifies each row in a table.
c.) A primary key can be made of multiple fields.
d.) Both a and b.
e.) All of the above.
Answer: e
Section: 11-1
49.
Level: Moderate
Page: 287
A foreign key:
a.) has nothing to do with the primary key.
b.) has different values than the primary key.
c.) is found in tables that don’t have a primary key.
d.) is related to the primary key of a different table.
e.) is a unique record in a table.
Answer: d
Section: 11-1
50.
Level: Hard
Page: 287
Which is not a program that can create a database?
a.) Access
b.) MySQL
c.) Oracle
d.) SQL Server
e.) All of the above can be used to create a database.
Answer: e
Level: Easy
11 - 5
Chapter 11 – Databases and ADO.NET
Section: 11-1
51.
Page: 288
What does the term DBMS stand for?
a.) Database Management Schema
b.) Database Management Style
c.) Database Management System
d.) Database Manipulation Schema
e.) Database Manipulation Style
Answer: c
Section: 11-1
52.
Level: Moderate
Page: 288
The normalization process is:
a.) used to remove redundant data.
b.) used to make the storage of data more efficient.
c.) not recommended for most databases.
d.) Both a and b.
e.) All of the above.
Answer: d
Section: 11-1
53.
Level: Hard
Page: 289
Which clause is required in an SQL query for getting information from a database?
a.) JOIN
b.) ON
c.) ORDER BY
d.) SELECT
e.) WHERE
Answer: d
Section: 11-2
54.
Level: Moderate
Page: 289
How many fields can be specified in the SELECT clause?
a.) 0
b.) 1
c.) 2
d.) 3
e.) As many as needed.
Answer: e
Section: 11-2
Level: Moderate
Page: 290
11 - 6
Chapter 11 – Databases and ADO.NET
55.
How many records are specified in the SELECT clause?
a.) 0
b.) 1
c.) 2
d.) 3
e.) As many as needed.
Answer: a
Section: 11-2
56.
Level: Hard
Page: 290
Which is the wildcard symbol for selecting all the fields in a table?
a.) @
b.) #
c.) ^
d.) *
e.) +
Answer: d
Section: 11-2
57.
Level: Easy
Page: 290
The WHERE clause is used to restrict the number of ____ retrieved by an SQL statement.
a.) fields
b.) records
c.) tables
d.) Both a and b.
e.) All of the above.
Answer: b
Section: 11-2
58.
Level: Easy
Page: 291
Which is not a valid type of JOIN?
a.) LEFT JOIN
b.) MIDDLE JOIN
c.) RIGHT JOIN
d.) INNER JOIN
e.) All of the above are valid types.
Answer: b
Section: 11-2
59.
Level: Moderate
Page: 293
The ORDER BY clause is used to sort:
a.) fields.
b.) records.
c.) tables.
d.) Both a and b.
e.) All of the above.
Answer: b
Section: 11-2
Level: Moderate
Page: 291
11 - 7
Chapter 11 – Databases and ADO.NET
60.
Which database is the ADO.NET SqlConnection object designed for?
a.) Access
b.) Microsoft SQL Server
c.) MySQL
d.) Oracle
e.) None of the above.
Answer: b
Section: 11-3
61.
Level: Easy
Page: 294
Which property of the database must the connection object contain?
a.) Location
b.) Type
c.) Query
d.) Both a and b.
e.) All of the above.
Answer: d
Section: 11-3
62.
Level: Moderate
Page: 294
Which is not a tab on the DataLink Property window?
a.) Advanced
b.) All
c.) Adapter
d.) Connection
e.) Provider
Answer: c
Section: 11-3
63.
Level: Hard
Page: 296
What information is specified in the Connection tab of the DataLink window?
a.) Database login
b.) Database name
c.) Database type
d.) Both a and b.
e.) All of the above.
Answer: d
Section: 11-3
64.
Level: Hard
Page: 297
The first step of configuring a DataAdapter is to select:
a.) an adapter object.
b.) a connection object.
c.) a database object.
d.) a dataset object.
e.) None of the above.
Answer: b
Section: 11-3
Level: Moderate
Page: 298
11 - 8
Chapter 11 – Databases and ADO.NET
65.
Which DataAdapter Query Type can be used with the Access database?
a.) Use SQL statements.
b.) Create new stored procedure.
c.) Use existing stored procedure.
d.) Both a and b.
e.) All of the above.
Answer: a
Section: 11-3
66.
Level: Easy
Page: 299
Which is not an ADO.NET DataAdapter Object?
a.) OleDbDataAdapter
b.) SQLDataAdapter
c.) QueryDataAdapter
d.) Both a and b.
e.) All of the above.
Answer: c
Section: 11-3
67.
Level: Easy
Page: 299
Which is the appropriate prefix for a DataAdapter object?
a.) da
b.) daa
c.) dad
d.) dt
e.) dta
Answer: a
Section: 11-3
68.
Level: Easy
Page: 300
Which type of object has the Generate Dataset method?
a.) Adapter object
b.) Connection object
c.) Database object
d.) Dataset object
e.) None of the above.
Answer: a
Section: 11-3
69.
Level: Moderate
Page: 300
Which is the appropriate prefix for a Dataset object?
a.) da
b.) das
c.) dat
d.) ds
e.) dst
Answer: d
Section: 11-3
Level: Easy
Page: 300
11 - 9
Chapter 11 – Databases and ADO.NET
70.
Which object does the data-aware control bind to?
a.) Dataset
b.) DataAdapter
c.) Connection
d.) Both a and b.
e.) All of the above.
Answer: a
Section: 11-4
71.
Level: Easy
Page: 300
What is the proper code to put data into the dataset called CustomerDataset using the
CustomerDataAdapter object?
a.) CustomerDataset.Fill(CustomerDataAdapter)
b.) CustomerDataAdapter.Fill(CustomerDataset)
c.) CustomerDataset.Load(CustomerDataAdapter)
d.) CustomerDataAdapter.Load(CustomerDataset)
e.) None of the above.
Answer: b
Section: 11-4
72.
Level: Moderate
Page: 303
Which object contains the Position property of the current record in a dataset?
a.) BindingContext
b.) BindingData
c.) DataBinding
d.) DataBound
e.) DataContext
Answer: a
Section: 11-4
73.
Level: Moderate
Page: 303
The first record in a dataset has a position property of:
a.) zero.
b.) one.
c.) any value defined by the programmer.
d.) Both a and b.
e.) All of the above.
Answer: a
Section: 11-4
74.
Level: Easy
Page: 303
Which below is specified by the DataMember Property?
a.) Connection object
b.) DataAdapter object
c.) Database field
d.) Database table
e.) Dataset object
Answer: d
Section: 11-5
Level: Moderate
Page: 305
11 - 10
Chapter 11 – Databases and ADO.NET
75.
Which below is specified by the DataSource Property?
a.) Connection object
b.) DataAdapter object
c.) Database field
d.) Database table
e.) Dataset object
Answer: e
Section: 11-5
76.
Level: Moderate
Page: 305
Which is a property of the DataGrid control?
a.) DataMember
b.) DataSource
c.) DataQuery
d.) Both a and b.
e.) All of the above.
Answer: d
Section: 11-5
Level: Easy
Page: 305
Fill in the Blank Questions
77.
A ___table___ is a collection of records.
Level: Easy
Section: 11-1
Page: 287
78.
A ___database___ can be thought of as a collection of related tables.
Level: Easy
Section: 11-1
Page: 287
79.
A primary key contains one or more ___fields___.
Level: Moderate
Section: 11-1
Page: 287
80.
Foreign key related to primary keys are found in ___different___ tables.
Level: Hard
Section: 11-1
Page: 287
81.
A ___primary key___ uniquely identifies each row of a table.
Level: Easy
Section: 11-1
Page: 287
82.
A ___linking__ table is used to identify the many-to-many relationship of two tables.
Level: Hard
Section: 11-1
Page: 289
11 - 11
Chapter 11 – Databases and ADO.NET
83.
A ___Database Management System (DBMS)___ is used to create and modify databases, as well
as get data into and out of the database.
Level: Moderate
Section: 11-1
Page: 288
84.
First, Second, and Third normal forms are all stages of the ___normalization___ process.
Level: Moderate
Section: 11-1
Page: 289
85.
The ___Structured Query Language (SQL)___ is a standard language used to retrieve data from a
database.
Level: Moderate
Section: 11-2
Page: 290
86.
The ___asterisk *___ is used as a wildcard that returns all of the fields in a table.
Level: Easy
Section: 11-2
Page: 290
87.
The SELECT clause determines which ___fields___ will be retrieved from the database.
Level: Easy
Section: 11-2
Page: 290
88.
The ___LIKE___ operator is used in the WHERE clause to match patterns of characters.
Level: Moderate
Section: 11-2
Page: 292
89.
The ORDER BY clause uses the ___ASC___ keyword sort data in ascending order and the
___DESC___ keyword to sort data in descending order.
Level: Moderate
Section: 11-2
Page: 292
90.
The JOIN clause requires both ___tables___ and ___columns (fields)___ to be specified in the
query.
Level: Hard
Section: 11-2
Page: 293
91.
The three types of ADO.NET objects required for exchanging data between a database and
VB.NET program are the ___Connnection___, ___DataAdapter___, and ___Dataset___ objects.
Level: Easy
Section: 11-3
Page: 294
92.
The term OLE stands for ___object linking and embedding___.
Level: Hard
Section: 11-3
Page: 294
93.
The ___connection string___ property of the OleDbConnection object contains the location of the
database being accessed.
Level: Moderate
Section: 11-3
Page: 295
11 - 12
Chapter 11 – Databases and ADO.NET
94.
The Microsoft Jet 4.0 OLE Provider is used when connecting to a(n) ___Access___ database.
Level: Moderate
Section: 11-3
Page: 296
95.
The ___DataAdapter___ Wizard can be used to configure the OleDbDataAdapter object.
Level: Easy
Section: 11-3
Page: 298
96.
The ___SQLDataAdapter___ object is used when connected to Microsoft SQL Server.
Level: Moderate
Section: 11-3
Page: 299
97.
The ___Query Builder___ button makes it easy create the SQL query associated with a
DataAdapter.
Level: Moderate
Section: 11-3
Page: 299
98.
The ___Dataset___ object holds the data generated by the SQL query in the DataAdapter.
Level: Easy
Section: 11-3
Page: 300
99.
The prefix for a DataAdapter object is ___da___.
Level: Easy
Section: 11-3
Page: 300
The prefix for a Dataset object is ___ds___.
Level: Easy
Section: 11-3
Page: 300
100.
101.
The ___data-aware___ control will automatically display data from the bound dataset.
Level: Easy
Section: 11-4
Page: 302
102.
The ___DataBound___ property holds the name of the field and dataset bound to the control.
Level: Moderate
Section: 11-4
Page: 302
103.
The Fill method is a member of the ___DataAdapter___ object.
Level: Moderate
Section: 11-4
Page: 303
104.
The ___BindingContext___ object monitors information about all data sources in a form.
Level: Moderate
Section: 11-4
Page: 303
105.
The ___SetDataBinding___ method is used to bind a DataGrid at run time.
Level: Hard
Section: 11-5
Page: 305
11 - 13
Chapter 11 – Databases and ADO.NET
106.
The DataGrid control uses the ___DataSource___ property to identify the source of the data being
displayed.
Level: Easy
Section: 11-5
Page: 305
107.
The DataGrid control uses the ___DataMember___ property when more than one bindable
element exists.
Level: Moderate
Section: 11-5
Page: 305
Essay Questions
108.
Describe the function and syntax of each part of an SQL SELECT statement, including the
ORDER BY and WHERE clauses?
The SELECT query has two mandatory elements: SELECT and FROM.
SELECT specifies which fields (or columns) will be returned from the database. Using an asterisk
will return all fields in a table.
FROM identifies the tables which contain the fields listed in the SELECT clause. Fields from
separate tables that have the same name must be qualified with the name of the table they come
from.
The ORDER BY clause is optional. If a field from the SELECT clause is placed after the ORDER
BY the rows of data are sorted in ascending order based on that field. The keywords ASC or
DESC can be placed after the field name to explicitly specify the order the data will be sorted in.
The WHERE clause is used to restrict which records are returned from the database. The
criteria for inclusion, based on a logical test (=, <>, >, <, >=, <=) of one or more fields, is
placed after the keyword WHERE. The criteria can also include the LIKE operator, which will
compare the field to a literal string mask which includes wild card symbols for a single character
(?) or multiple characters (*).
109.
Define the functions of the ADO.NET Connection, DataAdapter, and Dataset objects. Indicate
the naming convention for each type.
The Connection Object establishes a link to the database by specifying the physical location (i.e.
Network Directory), the type of database being accessed, and even the password information in
the Connection String property. This is analogous to having the phone number and a working
phone line for contacting a person who has information you need.
The DataAdapter object acts as a mediator which translates the language of VB.Net into the
unique language of the databases and vice-versa. The DataAdapter takes the SQL query and
translates it into a version the database understands. The DataAdapter also takes the output of
11 - 14
Chapter 11 – Databases and ADO.NET
the database and translates it into a version that the VB.NET program can use. This output
created by the DataAdapter is the Dataset Object.
The Dataset object is a local copy of the information requested by the SQL query. VB.NET can
then easily display this data in data-aware controls. Because this is local data any changes in
the original data in the database will not be reflected in the program (the local data is
disconnected from the database).
The prefix for the Connection, DataAdapter, and Dataset objects are cn, da, and ds respectively.
11 - 15
Download