Exam Prep Questions

Question 1

The data model for your application includes an array of Product objects named Products . Each Product object exposes public properties named ProductNumber and ProductName . You want to provide an interface that allows users to select the ProductNumber and see the corresponding ProductName . What should you do?

  • A. Create two TextBox controls. Bind the ProductNumber property to one TextBox control and the ProductName property to the other TextBox control. Provide navigation buttons to allow users to scroll through the data.

  • B. Create a DataGrid control and bind the Products array to the DataGrid control.

  • C. Create a DropDownList control. Set the Products array as the DataSource of the control. Bind the DataTextField property to the ProductNumber property, and bind the DataValueField property to the ProductName property. Bind a TextBox on the form to the SelectedItem.Value property of the DropDownList control. Add code to the SelectedIndexChanged property of the DropDownList control to invoke the DataBind() method of the TextBox control.

  • D. Create a TextBox control and a Label control. Bind the ProductNumber property to the TextBox control and the ProductName property to the Label control.

A1:

The correct answer is C. Binding the DropDownList control to the data source and responding to its SelectedIndexChanged event lets the DropDownList control transfer data from the source to the TextBox control. Answer A is incorrect because it requires searching for the data rather than choosing it. Answer B is incorrect because it displays all the data at once. Answer D is incorrect because it does not have any provision for choosing a ProductNumber .

Question 2

You have designed a Web form that will use a Repeater control with the ID of rptEmployees to display employee information. The form includes a SqlDataAdapter object, named sqlDataAdapter1 , that draws data from the Employees table and a DataSet object, named dsEmployees1 , that will contain the data. What code should you add to initialize the display when the page is loaded?

  • A.

     if(!IsPostBack) {     sqlDataAdapter1.Fill(dsEmployees1, "Employees");     rptEmployees.DataSource = dsEmployees1;     rptEmployees.DataMember = "Employees";     DataBind(); } 
  • B.

     if(IsPostBack) {     sqlDataAdapter1.Fill(dsEmployees1, "Employees");     rptEmployees.DataSource = dsEmployees1;     rptEmployees.DataMember = "Employees";     DataBind(); } 
  • C.

     if(!IsPostBack) {     sqlDataAdapter1.Fill(dsEmployees1, "Employees");     rptEmployees.DataSource = dsEmployees1;     rptEmployees.DataTextField = "Employees";     DataBind(); } 
  • D.

     if(IsPostBack) {     sqlDataAdapter1.Fill(dsEmployees1, "Employees");     rptEmployees.DataSource = dsEmployees1;     rptEmployees.DataTextField = "Employees";     DataBind(); } 
A2:

The correct answer is A. To initialize data when the page is loaded, you want to check that you're not in a postback. Answers B and D are incorrect because you need to execute the code when the page is being loaded for the first time. Answer C is incorrect because loading data requires a four-step process: Fill the DataSet , set the DataSource property of the Repeater , set the DataMember property of the Repeater , and call the DataBind() method to bind the data.

Question 3

Your application includes a database table that contains a list of course numbers and course names . You've used Server Explorer to create a SqlConnection object and a SqlDataAdapter object to access this data. You've also created a DataSet object named dsCourses1 to hold this data. Your form includes code to fill the DataSet object when it's loaded.

Now you want to display the list of courses in a ListBox control named lbCourses on your form. The ListBox control should show the course names and return the course numbers. Which of these code snippets should you use?

  • A.

     lbCourses.DataSource = dsCourses1; lbCourses.DataTextField = "CourseName"; lbCourses.DataValueField = "CourseNumber"; lbCourses.DataBind(); 
  • B.

     lbCourses.DataSource = dsCourses1.Tables["Courses"]; lbCourses.DataTextField = "CourseName"; lbCourses.DataValueField = "CourseNumber"; lbCourses.DataBind(); 
  • C.

     lbCourses.DataSource = dsCourses1.Tables["Courses"]; lbCourses.DataTextField = "CourseName"; lbCourses.SelectedItem = "CourseNumber"; lbCourses.DataBind(); 
  • D.

     lbCourses.DataTextField = "CourseName"; lbCourses.DataValueField = "CourseNumber"; lbCourses.DataBind(); 
A3:

The correct answer is B. The code in answer B performs the required task. Answer A is incorrect because it does not properly specify which data from the DataSet object to use. Answer C is incorrect because it neglects to bind the DataValueField property, which controls the value of the ListBox control. Answer D is incorrect because it neglects to set the DataSource property, without which there is no data to bind.

Question 4

Your application includes a SqlDataAdapter object named sqlDataAdapter1 that was created by dragging and dropping the Physicians table from a database to your form. Your application also includes a DataSet object named dsPhysicians1 that is based on this SqlDataAdapter object. Which line of code should you use to load the data from the database into the DataSet object?

  • A. dsPhysicians = sqlDataAdapter1.Fill("Physicians");

  • B. sqlDataAdapter1.Fill("dsPhysicians1", "Physicians");

  • C. sqlDataAdapter1.Fill("dsPhysicians1");

  • D. sqlDataAdapter1.Fill(dsPhysicians1, "Physicians");

A4:

The correct answer is D. This answer uses the correct syntax for the SqlDataAdapter.Fill() method. Answers A and C are incorrect because in a call to the Fill() method of a SqlDataAdapter object, you must specify the DataSet object to fill as an object and the table to fill as a string. Answer B is incorrect because dsPhysicians1 should not be within quotation marks.

Question 5

The application you're designing should display employee information on a DataGrid control using complex data binding. Your database contains a table of departments and a table of employees. The employees table has a foreign key that points back to the departments table. The application will communicate with the database via a slow WAN link. The list of departments changes approximately once every two months.

The form should display all the employees from a single department. Although users will view only one department at a time, they will frequently need to view several departments during the course of a session with the application.

How should you design the filtering for this form?

  • A. Build one view on the server for each department. At runtime, have the program use the appropriate view to retrieve the requested department.

  • B. Each time the user requests a department, retrieve all the data into a DataSet object. Then delete all the rows from the DataSet object that do not apply to this department.

  • C. Retrieve all the data into a DataSet object. Then use a DataView object with its RowFilter property set at runtime to retrieve individual departments as needed.

  • D. Build one form for each department. Each form should be based on a view that returns only the employees for that department. At runtime, open the appropriate form. Hide the form when the user is done so that it can be opened more quickly if it's needed a second time.

A5:

The correct answer is C. By setting the DataView.RowFilter at runtime, you can programmatically filter the data without having additional overhead or need for program modification. Answers A and D are incorrect because they require maintenance programming every time the list of departments changes. Answer B is incorrect because it retrieves more data than necessary over the slow WAN link.

Question 6

Your application is connected to a SQL Server database that contains customer and order information. You have a form in your application that fills a DataSet object with information from the Orders table that includes the CustomerID . The DataSet object is displayed on the form by using complex data binding to a DataGrid control.

Now you've been asked to display the CustomerName column from the Customers table in the DataGrid control, instead of the CustomerID column. How should you proceed?

  • A. Create a view in the SQL Server database that combines the Customers and Orders tables. Replace the DataSet object on the form with a new DataSet object based on this new view; then bind the new DataSet object to the DataGrid control.

  • B. Add a second DataSet object to the form, and base it on the Customers table from the database. Use each DataSet object to fill the appropriate columns of the DataGrid control.

  • C. Create a DataView object in code from the existing DataSet object. Filter the DataView object to remove the CustomerID column.

  • D. Add an array of Customer objects to your application and initialize it in code with customer names and IDs. Use a view to join this array to the existing DataSet object.

A6:

The correct answer is A. This answer lets you set up the DataGrid control so that it's automatically kept up-to-date. Answers B and C are incorrect because they provide no way to establish a relationship between the Customers and the Orders tables. Answer D is incorrect because it requires you to maintain the code to synchronize the array with the actual data in the database.

Question 7

Your application uses a DataList control to display course information. The information is supplied by a DataSet object named dsCourses1 . You want users to be able to edit the CourseName field, so you've created a Button control in the ItemTemplate with this code:

 <asp:Button id="btnEdit" runat=    "server" Text="Edit"    CommandName="Edit" /> 

You've also created an EditItemTemplate that includes a TextBox control with an ID of txtCourseName for editing the CourseName field. Which code should your application run when a user clicks the btnEdit button?

  • A.

     private void dlCourses_EditCommand(  Object sender, DataListCommandEventArgs e) {     dlCourses.EditItemIndex = e.Item.ItemIndex; } 
  • B.

     private void dlCourses_EditCommand(  Object sender, DataListCommandEventArgs e) {     dlCourses.EditItemIndex = e.Item.ItemIndex;     sqlDataAdapter1.Fill(dsCourses1, "Courses");     DataBind(); } 
  • C.

     private void dlCourses_EditCommand(  Object sender, DataListCommandEventArgs e) {     dlCourses.EditItemIndex = -1;     sqlDataAdapter1.Fill(dsCourses1, "Courses");     DataBind(); } 
  • D.

     private void dlCourses_EditCommand(  Object sender, DataListCommandEventArgs e) {     dlCourses.EditItemIndex = -1; } 
A7:

The correct answer is B. This answer follows the correct steps to place the selected row into edit mode, including setting the EditItemIndex property to the row number and then rebinding the data so that the edit controls are initialized . Answer A is incorrect because it doesn't rebind the data. Answers C and D are incorrect because they set the EditItemIndex property to -1 , which is how you end an edit, not how you begin one.

Question 8

You have developed a form with a DataList control that displays order information. One of the database columns you want to display on this form is named Tax . This column contains a currency value. Which binding expression should you use to display this value on the user interface, formatted as currency?

  • A.

     <%# DataBinder.Eval(Container.DataItem, "Tax") %> 
  • B.

     <%# "Tax" %> 
  • C.

     <%# "Tax", "{0:c}" %> 
  • D.

     <%# DataBinder.Eval(Container.DataItem, "Tax", "{0:c}") %> 
A8:

The correct answer is D. This answer correctly uses the DataBinder object's Eval() method to format the data. Answer A is incorrect because it won't apply any format. Answers B and C are incorrect because they fail to retrieve the correct information.

Question 9

The data model of your application includes a task list that might have from one to eight items in it. Each item is characterized by five pieces of information. You need to display the entire task list on a single form, and your users want to be able to see all the tasks at one time. What should you do?

  • A. Use simple data binding to display a single task in individual TextBox controls. Provide a DropDownList control to allow users to select the task to display.

  • B. Use the System.Reflection.Emit namespace to create the appropriate number of TextBox controls at runtime. Then use simple data binding to bind each task to a different set of controls.

  • C. Use complex data binding to display the task list in a DropDownList control.

  • D. Use complex data binding to display the task list in a DataGrid control.

A9:

The correct answer is D. The DataGrid control allows users to see all the tasks at the same time. Answers A and C are incorrect because they result in only one task being visible at a time. Answer B is incorrect because it uses a lot of complicated programming where a complex data binding call will suffice.

Question 10

You have an XML file containing information on customers. You plan to make this information available to your users by using simple data binding controls on the user interface. What must you do?

  • A. Transfer the data from the XML file to a data structure that implements the ICollection interface.

  • B. Create an XML Web Service to retrieve information from the file.

  • C. Store the XML file in a SQL Server database.

  • D. Set the Tag property of each control that you will use for data binding to XML .

A10:

The correct answer is A. You should import the data from the XML file to a data structure that implements the ICollection interface. Answers B, C, and D are incorrect because these options do not produce data that can be bound.



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