mIS 120 STUDY GUIDE FOR EXAM 2

advertisement
MIS 120 STUDY GUIDE FOR EXAM 2
NOTE: At least 35 the following questions will be in EXAM 2
Chapter 13: An introduction to database programming
1. The hardware components of a typical multi-user system are
a.
b.
c.
d.
the data access API, the SQL queries, and the DBMS
PCs, Macintoshes, and workstations
the clients, the server, and the network
the monitor, the hard drive, and the printer
ANS: C
2. A system that divides the processing between the clients and the server is called
a. a server-based system
c. a client/server system
b. an enterprise system
d. a mainframe system
ANS: C
3. To communicate with a DBMS, the application software sends
a. command objects
c. SQL queries
b. dataset requests
d. primary keys
ANS: C
4. To store the databases of a client/server system, the server requires
a. a database management system
b. an SQL query
c. a data access API
ANS: A
5. What does a relational database use to uniquely identify each row in a table?
a. indexes
b. foreign keys
c. non-primary keys
d. primary keys
ANS: D
6. What does a relational database use to relate tables in the database to each other?
a. indexes
b. foreign keys
c. non-primary keys
d. primary keys
ANS: B
7. If a row in one table is related to one or more rows in another table, the tables are said to have a
a. one-to-many relationship
b. one-to-one relationship
ANS: A
c. many-to-many relationship
Fall 007
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
8. The data that’s retrieved by a Select statement is called a
a. dataset
b. SQL query
c. data reader
d. result set
ANS: D
9. A join that returns records from related tables only if their related fields match is called
a. an outer join
b. an inner join
c. a cross join
d. a data join
ANS: B
10. Which of the following can a Select statement not do?
a. Retrieve data
b. Create calculated fields
c. Combine data from two tables
d. Modify selected data
ANS: D
11. The result set retrieved by the following Select statement contains records that have
Select Balance, Number
From Accounts
Where Balance < 0
a.
b.
c.
d.
all of the columns from the Accounts table
two of the columns from the Account table
all of the columns from the Accounts table where Balance is less than 0
two of the columns from the Accounts table where Balance is less than 0
ANS: D
Code example 13-1
Select VendorName, InvoiceNumber, InvoiceDate, InvoiceTotal
From Vendors Inner Join Invoices
On Vendors.VendorID = Invoices.VendorID
Where InvoiceTotal >= 500
Order By VendorName Desc
12. (Refer to code example 13-1.) If VendorName contains string data and InvoiceTotal contains decimal
values, how will the result set be ordered?
a. alphabetically starting with A
b. alphabetically starting with Z
c. numerically starting with 0
d. numerically starting with 500
ANS: B
13. (Refer to code example 13-1.) How many columns will the result set have?
a. 4
b. 5
ANS: A
c. 6
d. 7
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
14. (Refer to code example 13-1.) What table(s) does the data in the result set come from?
a. Vendors
b. Invoices
c. Vendors and Invoices
ANS: C
15. What does the following SQL statement add to the Terms table?
Insert Into Terms (TermsDueDays)
Values (90)
a.
b.
c.
d.
A row with a value of 90 for the TermsDueDays column
90 rows with a column of TermsDueDays
All rows where the TermsDueDays column has a value of 90
A TermsDueDays column with a default value of 90
ANS: A
16. When you use the .NET data provider objects to retrieve data from a database, you can store the data in an
object called a
a. business class
b. database
c. dataset
d. connection
ANS: C
17. What object does ADO.NET use to store a SQL statement?
a. data reader
b. data adapter
c. command
d. connection
ANS: C
18. What type of concurrency does ADO.NET use by default to check whether a row has changed before an
update or delete operation is performed?
a. optimistic
b. pessimistic
c. last in wins
d. first in wins
ANS: A
19. What is the primary function of a data adapter?
a.
b.
c.
d.
To define the connection to a database
To manage the flow of data between a client program and a database
To convert data to the format required by an application
To define a SQL operation to be performed
ANS: B
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
20. Which of the folowing statements is not true? An ADO.NET dataset object
a.
b.
c.
d.
has a structure similar to a relational database
can contain one or more tables
can define relationships between tables
can store command objects
ANS: D
21. Concurrency occurs when
a. an update or delete operation is refused
b. two or more users retrieve and then try to update data in the same row of a table at the
same time
c. an update or delete operation is resubmitted to the database
d. a program checks if a row has changed before updating or deleting it
ANS: B
22. ADO.NET’s disconnected data architecture
a.
b.
c.
d.
eliminates the need for concurrency control
requires additional system resources
allows the database connection to be closed after each operation
requires that programs be designed to retrieve and update a single row at a time
ANS: C
23. If you execute a Select statement directly instead of using a data adapter, what object do you use to read
the data that’s returned?
a.
b.
c.
d.
dataset
result set
data reader
data table
ANS: C
24. Which of the following is not true about a table adapter?
a.
b.
c.
d.
It can only be generated by the designer
It can contain a single query
It has a built-in connection object
It is similar to a data adapter
ANS: B
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
Chapter 14: How to use data sources with databases (part 1)
1. When you use a data source to get data from a database, you can
a. select just one table with all of its columns
b. select one or more tables with all of its columns
c. select just one table and just the columns that you want
d. select one or more tables with just the columns that you want from each table
ANS: D
2. If you save the connection string for a data source in the configuration file for the application,
a. the string is automatically adjusted if you change it in your Visual Basic code
b. you won’t have to change the string if the connection changes
c. you can change the string in just the configuration file if the connection changes
d. you can change the string in just one form if the connection changes
ANS: C
3. When you drag a data source onto a form, it adds a DataGridView control to the form and it adds all but
one of the objects that follow to the Component Designer tray. Which object is it?
a. BindingSource object
c. DataSet object
b. DataAdapter object
d. TableAdapter object
ANS: B
4. The BindingNavigator control (toolbar) that’s added to a form along with a DataGridView control can be
used to do all but one of the following. Which one is it?
a. navigate through the rows
c. undo an update
b. delete a row
d. add a row
ANS: C
5. When you edit the properties or columns of a DataGridView control, you can do all but one of the
following. Which one is it?
a. disable row navigation
c. reorder the columns
b. change column headers
d. disable row additions
ANS: A
6. The Fill method of a table adapter object that’s working with a SQL Server database will throw errors of
the
a. SqlException class
c. DataException class
b. OdbcException class
d. ConstraintException class
ANS: A
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
7. A NoNullAllowedException is thrown when the Update method of a table adapter object tries to update
the database with a record that has
a. null values in all of its columns
b. a null value in a single column
c. a null value in a column that doesn’t allow nulls
d. a null value for the primary key of a record
ANS: C
8. When a DBConcurrencyException is caught, your code should normally display a message to the user
that indicates that some rows weren’t updated and then
a. return to the form so the user can retry the updates
b. use the properties of the exception object to fix the rows that weren’t updated
c. use the Update method to try to update those rows again
d. use the Fill method to retrieve the current data from the database
ANS: D
9. When a DataGridView control throws a data error event, the event handler should normally
a. display a message that gives the row and column of the field that caused the error
b. disable the Update method so the row won’t be updated
c. refresh the DataGridView control so the user can re-enter the data for the current row
d. set the Cancel property of the EventArgs to true
ANS: A
10. The easiest way to test for concurrency errors is to
a. run the application from two different PCs
b. runs the application from two instances of Visual Studio
c. start the application twice from one instance of Visual Studio
ANS: B
11. When you use a data source with individual controls instead of a DataGridView control, you can do all
but one of the following. Which one is it?
a. use text boxes to display the values in the fields of each record in a table
b. use a toolbar to navigate from one record to another
c. format the data that’s retrieved from the database before it’s displayed
d. code exception handlers for DataError events
ANS: D
12. When you bind a combo box to a table in one data source, you can display the data from one column of
that table in the list of the combo box and use the selected value to
a. update another column in that table
b. update a column in a table of another data source
c. update another column in that table or a column in a table of another data source
d. update another column in that table and a column in a table of another data source
ANS: C
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
13. When you add a parameterized query to a data table, Visual Studio automatically adds a toolbar to the
form that lets you
a. navigate from one parameter to the next
b. navigate from one parameter value to the next
c. enter the parameter name and value that’s needed by the query
d. enter the parameter value that’s needed by the query
ANS: D
14. When you add a parameterized query to a data table, Visual Studio automatically generates the code
that’s required for executing the query, including a try-catch statement that catches
a. data provider exceptions
b. ADO.NET exceptions
c. all types of data exceptions
d. all types of exceptions
ANS: D
15. When you’re using data sources, an easy way to provide the default value for a column in a table that
doesn’t allow nulls is to
a. write a statement that adds the default value to the column
b. use the DataSet Designer to set the DefaultValue property for the column
c. use the Form Designer to set the DefaultValue property for the column
d. let the database supply its default value for the column
ANS: B
16. Because Visual Studio uses a disconnected data architecture when you use data sources, optimistic
concurrency is implemented by
a. the generated Visual Basic statements
c. the database constraints
b. the generated SQL statements
d. the database management system
ANS: B
17. In the statement that follows, the Fill method
Me.productsTableAdapter.Fill(Me.mmaBooksDataSet.Products)
a.
b.
c.
d.
loads the Products table in the dataset with data from the database
loads the Products table in the table adapter with data from the database
loads the Products table in the dataset with data from the table adapter
loads the Products table in the table adapter with data from dataset
ANS: A
18. In the statement that follows, the Update method
Me.productsTableAdapter.Update(Me.mmaBooksDataSet.Products)
a. updates the Products table in the dataset with data from the database
b. updates the Products table in the table adapter with data from the database
c. updates the database with data from the Products table in the dataset
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
d. updates the database with data from the Products table in the table adapter
ANS: C
19. In the statement that follows, the FillByCustomerID method
Me.customersTableAdapter.FillByCustomerID( _
Me.mmaBooksDataSet.Customers, customerID)
a. loads the Customers table in the dataset with data from the database in customerID
sequence
b. loads the customers table adapter with data from the database
c. loads the Customers table with one record from the database
d. loads the customers table adapter with one record from the database
ANS: C
20. When you use a data source, the SQL statements that are used to retrieve and update records can be found
in the SelectCommand and UpdateCommand properties of the
a.
b.
c.
d.
table adapter
binding source
data source
dataset
ANS: A
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
Chapter 16: How to use ADO.NET to write your own data access code
1. Which of the following is not set in a connection string?
a.
b.
c.
d.
security type
command type
database name
server name
ANS: B
2. Given a valid connection string named conString, which of the following statements creates a connection
for a SQL Server database?
a. conString.Open()
b. Dim con As New Connection(conString)
c. Dim con As New SqlConnection()
d.
con.SqlConnectionString = conString
Dim con As New SqlConnection(conString)
ANS: D
3. What two properties of a command object do you always need to set before you call one of the methods
of the command?
a.
b.
c.
d.
Connection and CommandType
Connection and CommandText
CommandText and Parameters
Command Type and CommandText
ANS: B
4. Which of the following is not a method of a command object?
a.
b.
c.
d.
ExecuteNonQuery
ExecuteActionQuery
ExecuteReader
ExecuteScalar
ANS: B
5. How is a parameter in a parameterized query for a SQL Server data adapter identified?
a.
b.
c.
d.
by a question mark (?)
by an asterisk (*)
by a named variable that begins with an at sign (@)
by a named variable that begins with a colon (:)
ANS: C
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
6. Which of the following code fragments does not use a named variable?
a.
b.
c.
d.
WHERE
WHERE
WHERE
WHERE
MovieID = @MovieID
Title = :MovieTitle
MovieYear = ?
Code = @MovieCode AND Title = @MovieTitle
ANS: C
7. Which group of statements creates a SQL Server parameter object named userIDParm that sets the value
of a parameter named UserID to the userID variable and sets its data type to Int32?
a. Dim userIDParm As New Parameter("UserID", userID)
userIDParm.Type = Type.Int32
b. Dim userIDParm As New Parameter("@UserID", userID)
userIDParm.DbType = DbType.Int32
c. Dim userIDParm As New SqlParameter("@UserID", userID)
userIDParm.DbType = DbType.Int32
d. Dim userIDParm As New SqlParameter("@UserID", userID)
userIDParm.Type = Type.Int32
ANS: C
8. Which of the following statements adds a parameter named userIDParm to an SQL statement that’s stored
in a command object named updateCommand?
a.
b.
c.
d.
updateCommand.Add(userIDParm)
updateCommand.Parameter(userIDParm)
updateCommand.Parameter.Add(userIDParm)
updateCommand.Parameters.Add(userIDParm)
ANS: D
9. Given a valid SqlCommand object named selectCommand, which of the following statements creates a
SqlDataReader object that returns a single row?
a. Dim employeeReader As SqlDataReader = _
selectCommand.ExecuteSqlDataReader(Single)
b. Dim employeeReader As SqlDataReader = _
c.
d.
selectCommand.GetSqlDataReader()
Dim employeeReader As SqlDataReader = _
selectCommand.ExecuteReader(CommandBehavior.SingleRow)
Dim employeeReader As SqlDataReader = _
selectCommand.GetSqlDataReaderSingle()
ANS: C
10. Given a valid SqlDataReader object named employeeReader, which of the following statements retrieves
the first column of the current row and stores it in a string variable named s?
a.
b.
c.
d.
Dim
Dim
Dim
Dim
ANS: B
s
s
s
s
As
As
As
As
String
String
String
String
=
=
=
=
employeeReader(0)
employeeReader(0).ToString
employeeReader(1)
employeeReader.GetFirstColumn()
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
11. Given a SqlCommand object named updateCommand that contains a valid SQL Update statement, which
of the following statements executes the Update statement and returns the number of rows that were
affected by that statement?
a.
b.
c.
d.
Dim
Dim
Dim
Dim
count
count
count
count
As
As
As
As
Integer
Integer
Integer
Integer
=
=
=
=
updateCommand.ExecuteNonQuery()
updateCommand.ExecuteActionQuery()
updateCommand.ExecuteScalar()
updateCommand.ExecuteQuery()
ANS: A
12. Given a DataSet object named employeesDataSet, which of the following refers to the first table in that
dataset?
a.
b.
c.
d.
employeesDataSet.Table("Employees")
employeesDataSet.Tables(0)
employeesDataSet.DataTable(0)
employeesDataSet.DataTables(0)
ANS: B
13. What must be defined before you call the Fill method of a data adapter?
a.
b.
c.
d.
The Select statement for the data adapter
The Insert, Update, and Delete statements for the data adapter
The schema information for the table where the data will be stored
The table mappings for the data adapter
ANS: A
14. Which of the following is not a member of the MissingSchemaAction enumeration that is used with the
Fill method of a data adapter object?
a.
b.
c.
d.
Add
AddWithKey
Update
Error
ANS: C
15. Which of the following statements fills a data table named Employees in a dataset named
employeesDataSet using a data adapter named employeesDataAdapter?
a.
b.
c.
d.
employeesDataSet.Fill(employeesDataAdapter,
employeesDataAdapter.Fill(employeesDataSet,
employeesDataAdapter.Fill(employeesDataSet,
employeesDataSet.Fill(employeesDataAdapter,
ANS: B
"Employees")
"Employees")
Employees)
Employees)
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
16. Which of the following statements is not true about a transaction?
a. A transaction can’t be rolled back after it has been committed.
b. A transaction is a group of SQL statements that are combined into a logical processing
unit.
c. A transaction object is associated with one or more command objects.
d. A transaction object is instantiated by using the BeginTransaction method of a command
object.
ANS: D
17. Given a transaction object named salesTran and a connection object named connection, which of the
following statements makes all changes made by the transaction permanent?
a. salesTran.Commit()
b. salesTran.EndTrans()
c. salesTran.Commit(connection)
d. salesTran.EndTrans(connection)
ANS: A
18. Given a transaction object named salesTran and a command object named salesCmd, which of the
following statements associates the command with the transaction?
a. salesTran += salesCmd
b. salesTran.Add(salesCmd)
c. salesCmd.Transaction = salesTran
d. salesTran.Transaction = salesCmd
ANS: C
19. You can use a SQLCommandBuilder object to generate the Insert, Update, and Delete commands
a. for a data adapter that uses any SELECT statement
b. for a data adapter that uses a SELECT statement that has a primary key
c. for a dataset that uses any SELECT statement
d. for a dataset that uses a SELECT statement that doesn’t do a join
ANS: B
20. Which of the following declarations could be used for a function in a database class that deletes an
employee row in a database table and returns a true/false value if the operation was successful? Assume
that this method enforces optimistic concurrency.
a. Public Shared Function DeleteEmployeeData(ByVal employeeID As Integer) _
As Boolean
b. Public Shared Function DeleteEmployeeData(ByVal employee As Employee) _
As Boolean
c. Public Shared Function DeleteEmployee(ByVal employeeID As Integer) _
As Integer
d. Public Shared Function DeleteEmployee(ByVal employee As Employee) _
As Integer
ANS: B
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
Chapter 17: How to use data sources with business objects
MULTIPLE CHOICE
1. The shortcoming that you encounter when you use data sources with databases is that you
a. can’t get the benefits of data binding
b. can’t separate the presentation code from the database code
c. can’t use optimistic concurrency
d. can’t use data adapters
ANS: B
2. The shortcoming that you encounter when you use ADO.NET code for database access without using data
sources is that you
a. can’t get the benefits of data binding
b. can’t separate the presentation code from the database code
c. can’t use optimistic concurrency
d. can’t use data adapters
ANS: A
3. Which of the following statements is not true about the use of data sources with business objects?
a. You have to write the code for populating the business objects.
b. You don’t get the benefit of data binding.
c. You can develop 3-layer applications.
d. You have to write the code for inserting, updating, and deleting the records in a database.
ANS: B
4. To create an object data source, you need to do all but one of the following. Which one is it?
a. Write the code for the business object.
b. Store the business object in a class library.
c. Select the database table and columns that you’re going to use for the business object.
d. Select the object that you wish to use for the object data source.
ANS: C
5. When a DataGridView control is bound to an object data source, you can use the CurrencyManager
object to synchronize the grid with the object data source
a. whenever rows are added to or deleted from the database
b. whenever a row is updated in the database
c. each time the user navigates to a new row
d. each time the user navigates to a new row or a new column
ANS: A
6. When you use transactions with object data sources, you can issue all of the SQL commands for the
transaction in a try block
a. by themselves
MIS 120 STUDY GUIDE FOR EXAM 2
Fall 007
b. along with the commit method for the transaction
c. with the commit method in the finally block
d. with the commit method after the try-catch statement
ANS: B
7. To make it easy to change the connection for all of the database classes in an application when you use
object data sources, it’s best to
a. use the application configuration file to provide the connection string
b. provide a public property in one of the database classes that holds the required connection
string
c. provide a public method in one of the database classes that returns the connection object
d. provide a method in each database class that returns the connection object
ANS: C
8. You can bind a combo box to an object data source during design time by using the binding source, but
you need to override that binding at runtime
a. when you establish the connection to the database
b. when you create the object that the combo box should be bound to
c. when the user selects a new item from the combo box
d. whenever the data in the database changes
ANS: B
Download