Exam Prep Questions

Question 1

Your SQL Server database contains a table called Sales with these columns :

SalesID (int, identity)

StoreNumber (int)

Sales (int)

You want to create a stored procedure that accepts as inputs the store number and sales, inserts a new row in the table with this information, and returns the new identity value. Which SQL statement should you use?

  • A.

     CREATE PROCEDURE procInsertSales  @StoreNumber int, @Sales int, @SalesID int AS  INSERT INTO Sales (StoreNumber, Sales)      VALUES (@StoreNumber, @Sales)   SELECT @SalesID = @@IDENTITY 
  • B.

     CREATE PROCEDURE procInsertSales   @StoreNumber int, @Sales int,   @SalesID int OUTPUT AS   INSERT INTO Sales (SalesID,      StoreNumber, Sales)   VALUES (@SalesID, @StoreNumber, @Sales) 
  • C.

     CREATE PROCEDURE procInsertSales   @StoreNumber int, @Sales int,   @SalesID int OUTPUT AS   INSERT INTO Sales (SalesID,    StoreNumber, Sales)   VALUES (0, @StoreNumber, @Sales)   SELECT @SalesID = @@IDENTITY 
  • D.

     CREATE PROCEDURE procInsertSales   @StoreNumber int, @Sales int,   @SalesID int OUTPUT AS   INSERT INTO Sales (StoreNumber, Sales)   VALUES (@StoreNumber, @Sales)   SELECT @SalesID = @@IDENTITY 
A1:

Answer D is correct. It correctly inserts the values and returns the identity value. Answer A is incorrect because it does not indicate that @SalesID is an output parameter. Answers B and C attempt to insert values into the identity column, rather than letting SQL Server assign the new value, so they are incorrect.

Question 2

Your application includes 15 double-precision, floating-point numbers you want to write out to a disk file. You'd like to minimize the size of the disk file. Which object should you use to write the file?

  • A. FileStream

  • B. StreamWriter

  • C. BinaryWriter

  • D. XmlTextWriter

A2:

Answer C is correct. The BinaryWriter object provides a compact format for data storage on disk, as long as you don't need the data to be human readable. Answers A, B, and D are incorrect because these objects store the data as ASCII text, which takes more space.

Question 3

Your application includes a DataSet object that contains a DataTable object named Suppliers . This DataTable object contains all the rows from the Suppliers table in your database. You want to bind an object to a DataGrid control on a form such that the DataGrid control displays only the suppliers from Pennsylvania. What should you do?

  • A. Create a filtered array by calling the DataTable.Select() method on the suppliers DataTable object and bind the array to the DataGrid control.

  • B. Create a new SqlCommand object to retrieve only suppliers from Pennsylvania. Use a new SqlDataAdapter object to fill a new DataSet object with these suppliers. Then bind the new DataSet object to the DataGrid control.

  • C. Use a foreach loop to move through the entire suppliers DataTable object. Each time you find a DataRow object representing a supplier from Pennsylvania, bind that DataRow object to the DataGrid control.

  • D. Create a filtered DataView object from the suppliers DataTable object and bind the DataView object to the DataGrid control.

A3:

Answer D is correct. The DataView class provides a data-bindable and customized view of a DataTable suitable for sorting, filtering, searching, editing, and navigation. Answers A and C are incorrect because these answers do not give you objects that can be bound to the DataGrid control. Answer B is incorrect because retrieving the data from the database a second time will be slower than filtering it from the existing DataTable object.

Question 4

Your application needs to return the total number of customers in a database. What is the fastest way to do this?

  • A. Write ad hoc SQL queries to return the total number of customers. Use the SqlCommand.ExecuteScalar() method to execute the SQL statement.

  • B. Write ad hoc SQL queries to return the total number of customers. Use the SqlDataAdapter.Fill() method to execute the SQL statement.

  • C. Create a stored procedure to return the total number of customers. Use the SqlCommand.ExecuteScalar() method to execute the stored procedure.

  • D. Create a stored procedure to return the total number of customers. Use the SqlDataAdapter.Fill() method to execute the stored procedure.

A4:

Answer C is correct. Stored procedures execute more quickly than the corresponding ad hoc SQL statements because stored procedures are stored in the database in compiled form. Answers A and B are incorrect because they use ad hoc SQL queries that can be slower than stored procedures. Answer D is incorrect because using the ExecuteScalar() method is faster than filling a dataset object for returning a single value.

Question 5

Your application needs to retrieve a list of customer balances from a SQL Server database. The application should move through the list once, processing each balance in turn . The application does not need to write to the database. Your solution should process the data as quickly as possible. Which object should you use to hold the list in the data model?

  • A. DataSet

  • B. SqlDataReader

  • C. DataTable

  • D. DataView

A5:

The correct answer is B. The SqlDataReader object gives you a fast, forward-only, read-only view of the data. Answers A, C, and D are incorrect because these objects have significant overhead when compared to SqlDataReader .

Question 6

Your application uses a SqlDataReader object to retrieve information about customer balances. When you find a past-due balance, you want to write a new entry to a billing table by executing a stored procedure in the same database. You have used a SqlCommand object to represent the stored procedure. Calling the ExecuteNonQuery() method of the SqlCommand object is causing an error. What is the most likely cause of this error?

  • A. You must use a SqlDataAdapter object to execute the stored procedure.

  • B. You must use an ad hoc SQL statement rather than a stored procedure to insert new rows in a database.

  • C. You are using the ExecuteNonQuery() method of the SqlCommand object, and you should be using the ExecuteScalar() method instead.

  • D. You are using the same SqlConnection object for both the SqlDataReader object and the SqlCommand object, and the SqlDataReader object is still open when you try to execute the SqlCommand object.

A6:

The correct answer is D. While a SqlDataReader object is open, you cannot execute other commands on the SqlConnection object the SqlDataReader object is using. Answer A is incorrect because the SqlCommand object can be used to execute the stored procedure. Answer B is incorrect because stored procedures can be used to insert new rows in a database. Answer C is incorrect because the ExecuteScalar() method is used to return just a single value; however, the insert operation does not return any rows, so using the ExecuteNonQuery() method is correct.

Question 7

Your application has two FileStream objects. The fsIn object is open for reading, and the fsOut object is open for writing. Which code snippet would copy the contents of fsIn to fsOut using a 2KB buffer?

  • A.

     Int32[] buf = new  Int32[2048]; Int32 intBytesRead; while((intBytesRead =        fsIn.Read(buf, 0, 2048)) > 0)     fsOut.Write(buf, 0, intBytesRead); fsOut.Flush(); fsOut.Close(); fsIn.Close(); 
  • B.

     Int32[] buf = new  Int32[2048]; Int32 intBytesRead; while((intBytesRead =         fsIn.Read(buf, 0, 2048)) > 1)     fsOut.Write(buf, 0, intBytesRead); fsOut.Flush(); fsOut.Close(); fsIn.Close(); 
  • C.

     Byte[] buf = new  Byte[2048]; Int32 intBytesRead; while((intBytesRead =          fsIn.Read(buf, 0, 2048)) > 0)     fsOut.Write(buf, 0, intBytesRead); fsOut.Flush(); fsOut.Close(); fsIn.Close(); 
  • D.

     Byte[] buf = new  Byte[2048]; Int32 intBytesRead; while((intBytesRead =     fsIn.Read(buf, 0, 2048)) > 1)     fsOut.Write(buf, 0, intBytesRead); fsOut.Flush(); fsOut.Close(); fsIn.Close(); 
A7:

The correct answer is C. This answer correctly uses the Read() and Write() methods of the FileStream class to copy the contents of a file using a 2KB buffer. The Read() method returns the number of bytes read, so answers B and D fail when there is 1 byte in the file. The Read() method reads to a byte array, so answers A and B will fail because the buffer has the wrong data type.

Question 8

Your application allows the user to edit product data on a DataGrid control, which is bound to a DataSet object. The DataSet object is filled through a SqlDataAdapter object. The InsertCommand, UpdateCommand , and DeleteCommand properties of the SqlDataAdapter object are set to SqlCommand objects, and you have tested the SQL in those SqlCommand objects.

When users submit the page, none of their changes are saved to the database, and they do not receive any errors. What could be the problem?

  • A. You have neglected to call the SqlDataAdapter.Update() method in your code.

  • B. The users do not have permission to write to the database.

  • C. You have neglected to fill the DataSet object from the DataGrid control after the users finish editing the data.

  • D. The DataSet object is a read-only object.

A8:

The correct answer is A. If you do not call the SqlDataAdapter.Update() method, all changes to the data model are lost. Answer B is incorrect because it returns an error to the users. Answer C is incorrect because a bound DataSet object automatically reflects changes to the DataGrid control. Answer D is incorrect because DataSet objects are designed to be edited.

Question 9

Your application reads an XML file from disk into an XmlDocument object; then it modifies some of the nodes in the document. Which of the following classes should you use to write the modified XmlDocument object back to disk?

  • A. XmlTextWriter

  • B. FileStream

  • C. StreamWriter

  • D. BinaryWriter

  • E. TextWriter

A9:

The correct answer is A. The XmlTextWriter class is designed to write XML files, preserving the proper XML structure. Answers B, C, D, and E are incorrect because, although these classes can process an XML file as a set a characters or bytes, these classes have no knowledge of the XML structure of the file.

Question 10

You allow users to edit product information on a DataGrid control bound to a DataSet object. When a user clicks the Update button on the form, you call the SqlDataAdapter.Update() method to cause the changes from the DataSet object to persist to the underlying database.

Users reports that new records and updated rows are saved properly but deleted rows are reappearing the next time they run the application. What could be the problem?

  • A. The users do not have permission to update the underlying table.

  • B. The Update() method does not delete rows.

  • C. Someone is restoring an old version of the database between the two executions of the program.

  • D. The DeleteCommand property of the SqlDataAdapter object points to a SqlCommand object that does not properly delete rows.

A10:

The correct answer is D. Answers A and C are incorrect because, if this would have been the case, none of the changes would have been saved. Answer B is incorrect because the Update() method can delete rows from the data source if the corresponding row has been deleted from the DataSet object.



MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
ISBN: 789729016
EAN: N/A
Year: 2005
Pages: 191

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