wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C# Chapter 6

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

Your application needs to store the product image out to a disk file. You’d like to minimize the size of this disk file. Which of the following objects should you use to write the file?

a)

FileStream

b)

StreamWriter

c)

BinaryWriter

d)

XmlWriter

2.

Your C# program needs to return the total number of customers in a database. The program will be used several times a day. What is the fastest way to return this information from your program?

a)

Write a SQL query and use the SqlCommand.ExecuteScalar method to execute the query.

b)

Create a stored procedure to return the total number of customers, then use the SqlCommand.ExecuteScalar method to execute the stored procedure

c)

Write a SQL query and use the SqlDataAdapter.Fill method to execute the query.

d)

Create a stored procedure to return the total number of customers, then use the SqlDataAdapter.Fill method to execute the stored procedure.

3.

You need to modify the records in a Products table by marking certain products as Discontinued. However, you need to do this only when the UnitsInStock and UnitsOnOrder are both zero. Which of the following SQL statements should you use?

a)

INSERT

b)

SELECT

c)

UPDATE

d)

DELETE

4.

You need to update the Region fields for customers in Japan. You write the following SQL UPDATE statement: UPDATE Customers

SET Region = 'EastAsia'

You test the query on a test database and find that more records were affected than you expected. You need to correct the SQL statement. What should you do?

a)

Add a WHERE clause to the UPDATE statement.

b)

Add an additional SET clause to the UPDATE statement.

c)

Add a GROUP BY clause to the UPDATE statement.

d)

Add a HAVING clause to the UPDATE statement.

5.

You are developing an application that needs to retrieve a list of customers from a SQL Server database. The application should move through the list sequentially once, processing each customer’s record. Which of the following classes should you use to hold the customer list in order to achieve maximum performance?

a)

DataSet

b)

DataTable

c)

DataView

d)

SqlDataReader

6.

The application you are developing needs to read data from a flat file that include items such as a five-digit integer key, followed by a 20-character customer name, followed by two date and time fields. Which of the following classes should you use?

a)

FileStream

b)

StreamReader

c)

BinaryReader

d)

DataReader

7.

You are developing an application that will need to copy data from a SQL Server view to a DataSet. You name the DataSet object dsData. Which of the following methods should you use to copy the data?

a)

Fill

b)

InsertCommand

c)

SelectCommand

d)

Update

8.

You are developing an application that manages customers and their orders. Which of the following situations is not a good candidate for implementation with stored procedures in your application?

a)

Retrieving the list of all customers in the database

b)

Retrieving the list of all orders for particular customers

c)

Inserting a new order into the Orders table

d)

Ad hoc querying by the database administrator

9.

Your application connects to a SQL Server database that contains a table called Employees with the following columns:

EmployeeID (int, identity)

EmployeeType (char(1))

EmployeeDate (datetime)

You need to write a query that deletes all rows from the table where the EmployeeType value is either C or T. You do not want to delete any other rows. Which statement should you use?

a)

DELETE FROM Employees WHERE EmployeeType LIKE '[CT]'

b)

DELETE FROM Employees WHERE EmployeeType LIKE '[C-T]

c)

DELETE FROM Employees WHERE EmployeeType LIKE 'C' OR 'T'

d)

DELETE * FROM Employees WHERE EmployeeType IN ('C', 'T')

10.

Your application includes a SqlDataAdapter object named sqlDataAdapter that connects to the Employees table. Based on this SQLDataAdapter, your application also includes a DataSet object dsEmployees. What line of code should you use to load the data from the database into the DataSet object?

a)

dsEmployees = sqlDataAdapter.Fill("Employees");

b)

sqlDataAdapter.Fill("dsEmployees", "Employees")

c)

sqlDataAdapter.Fill(dsEmployees);

d)

sqlDataAdapter.Fill(dsEmployees, "Employees");