.NET问题集

(1). TestKing buys and sells used refrigerators. External vendors frequently send you XML documents that list one type of used appliances for sale. The documents that you receive contain either only washers or only refrigerators as in the following example.

<!- A document with refrigerators -->
    < saleList>
        < refrigerators>
            < refrigerator type=?± freezer on bottom?± , price=?± 210?±/>
        < refrigerators>
    </ saleList>

<!- A document with washers -->
    < saleList>
        < washers>
            < washer type=?± front load?± , price=?± 145?±/>
        < washer type=?± top load?± , price=?± 130?±/>
        </ washers>
    </ saleList>

All incoming XML documents are loaded into a MemorySystem object named usedList. You need to automate a process that will discover XML documents contain refrigerator elements. As soon as you ascertain that a document contains refrigerators, you can stop processing the document. You decide to use Visual studio . NET to develop an application that will contain a Boolean variable named hasRefrigerator. A value of True for this variable means that a document contains refrigerator elements. A value of false means that it does not. You want to ensure that the discovery process occurs as quickly as possible. What should you do?

A. Create an XmlDocument object and load it from usedList.
     Use the SelectSingleNode method to search the XmlDocument object for the saleList/refrigerators node.
     If this node is found, set hasRefrigerator to True.
     Otherwise, set hasRefrigerator to False.

B. Create an XmlXPathDocument object and load it from usedList.
     Use an XPathNavigator object to search the XmlXPathDocument for the saleList/ refrigerators node.
     If this node is found, set hasRefrigerator to True.
    Otherwise, set hasRefrigerator to False.

C. Create an XmlTextReader object on usedList.
     Loop through usedList by using the MoveToContent method of the XmlTextReader object and
     comparing for the saleList/ refrigerators node.
     If this node is found, set hasRefrigerator to True.
     Otherwise, set hasRefrigerator to False.

D. Create a DataSet object and use its ReadXml method to load usedList into the object.
     If the Count property of the Rows collection of the ?° refrigerators?± entry in the object is not
     equal to zero, set hasRefrigerator to True.
     Otherwise, set hasRefrigerator to False.

Answer: A

(2) You create an XML web service that retrieves data from Microsoft SQL Server database. You instantiate a SqlConnection object named TestKConnection and set the Max Pool Size property of the connectionString to 50. All 50 connections are now in use. However, a request for connection number 51 is received. What is the most likely result?

A. An exception is immediately thrown.

B. The current connection pool is expanded by 50 additional connections.

C. A new connection pool is created that has the same maximum number of connections.

D. The request is queued until a connection becomes available or until the timeout limit is reached.

Answer: D

(3) You have a strongly types DataSet object named TestKingDataSet. This object contains three DataTable objects named Customers, Orders and OrderDetails. Customers and Orders have a data column named CustomerID. Orders and OrderDetails have a data column named OrderID. Orders have a foreign key constraint between Customers and Orders on CustomerID. OrderDetails has a foreign key constraint between Orders and OrderDetails on OrderID. You want to populate Customers, Orders and OrderDetails with data from Microsoft SQL Server database. In which order should you fill the Data table objects?

A. Customers  OrderDetails  Orders

B. OrderDetails  Orders  Customers

C. Customers  Orders  OrderDetails

D. Orders  OrderDetails  Customers

Answer: C

(4) Your Microsoft SQL Server 6.5 database contains a table named TestKingPurchases that consists of more than 1 million rows. You are developing an application to populate a DataReader object with data from TestKingPurchases. You want to ensure that the application processes the data as quickly as possible. You create a SQL SELECT statement in a local variable named tkSQLSelect. You need to initiate a SqlConnection object and a SqlCommand object you will use to populate the DataReader object. Which code segment should you use?

A. Dim myConnection As New OleDbConnection ( myOleDbConnectionString)
    Dim tkCommand As New OleDbCommand ( tkSQLSelect)

B. Dim myConnection As New OleDbConnection ( myOleDbConnectionString)
    Dim tkCommand As New OleDbCommand ( tkSQLSelect, myConnection)

C. Dim myConnection As New SqlConnection ( mySqlConnectionString)
    Dim tkCommand As New SqlCommand (tkSQLSelect)

D. Dim myConnection As New SqlConnection ( mySqlConnectionString)
    Dim tkCommand As New SqlCommand ( tkSQLSelect, myConnection)

Answer: B

(5) Your Microsoft SQL Server database has a stored procedure named GetTestKingCustomer. getTestKingCustomer accepts one parameter named @ CustomerID and returns the appropriate company name. You initiate a SqlCommand object named myCommand. You need to initialize myCommand to return the company name for @ CustomerID with a value of "ALFKI".

Which code segment should you use?

A. myCommand. CommandText = " TestKingCustomer, ALFKI"
    myCommand. Parameters. Add (?°@ CustomerID?±)

B. myCommand. CommandText = " TestKingCustomer"
    myCommand. Parameters. Add (?° TestKingCustomer?±, ?° ALFKI?±)

C. myCommand. CommandText = "CustomerID"
    myCommand. Parameters. Add (?° TestKingCustomer?±, ?° ALFKI?±)

D. myCommand. CommandText = " TestKingCustomer"
    myCommand. Parameters. Add (?°@ CustomerID?±, ?° ALFKI?±)

Answer: D

(6) You have a DataSet object named myDataSet. This object contains two DataTable objects named Customers and Orders. Customers has a column named CustomerID, which is unique to each customer. Orders also has a column named CustomerID. You want to use the GetChildRows method of the DataRow object to get all orders for the current customers. What should you do?

A. Add a foreign key constraint on CustomerID of Orders between Customers and Orders.

B. Add a data relation to myDataSet on OrderID between Customers and Orders.

C. Create a unique constraint on CustomerID of Customers.

D. Create a primary key on CustomerID of Customers.

Answer: B

(7) You are developing an application that queries a table named Products in a Microsoft SQL Server database. The query will be stored in a string variable named TKQuery. The query includes the following SQL code.

SELECT * FROM Products For XML AUTO

You must iterate the query results and populate an HTML table with product information. You must ensure that your application processes the results as quickly as possible. What should you do?

A. Use a SqlDataAdapter object and set its SelectCommand property to TKQuery.
    Use the Fill method of the SqlDataAdapter object to read the data into a DataSet object.
    Loop through the associated rows to read the data.

B. Use a SqlDataAdapter object and set its SelectCommand property to TKQuery.
    Use the Fill method of the SqlDataAdapter object to read the data into a DataSet object.
    Use the ReadXml method of the DataSet object to read the data.

C. Set the SqlCommand object?ˉs Command Text to TKQuery.
    Use the ExecuteReader method of the SqlCommand object to create a SqlDataReader object.
    Use the Read method of the SqlDataReader object to read the data.

D. Set the SqlCommand object?ˉs Command Text to TKQuery.
    Use the ExecuteXmlReader method of the SqlCommand object to create a XmlReader object.
    Use the XmlReader object to read the data.

Answer: D

(8) You use a function to maintain a table named Categories in a Microsoft SQL Server database. The function creates a DataTable object named Categories in a DataSet object named categoriesDataSet. These two objects capture all insertions, updates and deletions to the Categories table. The function instantiates a SqlDataAdapter object named TKDataAdapter. This object is configured to select, insert, update and delete rows in the Categories DataTable object. You need to update the database to include the changes in the Categories DataTable object and capture all data errors in a batch after all rows have been processed. Which code segment should you use?

A. Try
      TKDataAdapter. Update ( CategoriesDataSet, ?° Categories?±)
      Catch mySqlException as SqlException
      Dim myDataRow( ) As DataRow = CategoriesDataSet. Tables ( 0). GetErrors ( )
    End Try

?? Code to process errors goes here.

B. TKDataAdapter. ContinueUpdateOnError = True
    Try
      TKDataAdapter. Update ( CategoriesDataSet, ?° Categories?±)
      Catch mySqlException as SqlException
      Dim myDataRow( ) As DataRow = CategoriesDataSet. Tables ( 0) . GetErrors ( )
    End Try

?? Code to process errors goes here.

C. TKDataAdapter. Update ( CategoriesDataSet, ?° Categories?±)
     If categoriesDataSet. Tables( 0). HasErrors Then
        Dim myDataRow ( ) As DataRow = CategoriesDataSet. Tables( 0). GetErrors ( )
        ?? Code to process errors goes here.
     End If

D. TKDataAdapter. ContinueUpdateOnError = True
     TKDataAdapter. Update ( CategoriesDataSet, ?° Categories?±)
     If categoriesDataSet. Tables ( 0). HasErrors Then
        Dim myDataRow ( ) As DataRow = CategoriesDataSet. Tables( 0). GetErrors ( )
       ?? Code to process errors goes here.
     End If

Answer: D

(9) Your company frequently receives product information from external vendors in the form of XML data. You receive XML document files, an . xdr schema file, and an . xsd schema file. You need to write code that will create a typed DataSet object on the basis of product information. Your code will be used in several Visual studio . NET applications to speed up data processing. You need to create this code as quickly as possible. What should you do?

A. Create the code manually.

B. Use XmlSerializer. Serialize to generate the code.

C. Use the XmlSerializer. Deserialize to generate the code.

D. Use the Xml Schema Definition tool ( Xsd. exe) to generate the code.

Answer: D

(10) You create a DataSet object named TestKingProductsDataset that contains product information from a Microsoft SQL Server database. This object has a primary key on a column named ProductID. You want to create a new DataSet object that has the same structure as TestKingProductsDataset, including the primary key. You want the new DataSet object to be empty of data. Which code segment should you use?

A. Dim NewDataSet As DataSet = TestKingProductsDataset. Clone

B. Dim NewDataSet As DataSet = TestKingProductsDataset. Copy

C. Dim NewDataSet as New DataSet ( )
    newDataSet. Tables. Add (?° TestKingProductsDataset?±)

D. Dim newDataSet as New Dataset ( )
    newDataSet. Tables. Add ( TestKingProductsDataset. Tables ( 0))

Answer: A