Exercises

  1. In the TestConsumer project you created earlier today, you didn't implement code for all the methods and properties you wrote in the myComponent Class Library application. Do the following to finish off the application:

    • In the Form_Load event, write code that calls the GetAuthors method and fill the DataGrid on the form with the results. This demonstrates how to pass ADO.NET data from a component to a client application.

    • In the DoName_Click event, add code that sets the FirstName and LastName properties and then display the FullName property in a MessageBox. This demonstrates how to set and retrieve properties in a component.

  2. Create a new ASP.NET application with a DataGrid, a TextBox, and a CommandButton.

    Add a Class Library project to the solution. In the class library, create two methods with the following characteristics:

    • A GetAuthors method that retrieves all authors from the Pubs database. This method should return a SqlDataReader.

    • A GetAuthorByID method that takes the Au_ID field as a parameter to retrieve a specific author from the database. This method should return a SqlDataReader.

    In the code-behind for the ASPX page that has the CommandButton and the TextBox, write code that fills the DataGrid with the results from the component based on the SqlDataReader that's returned.

    The goal of this exercise is to get you familiar with passing ADO.NET data to an ASP.NET application and using databinding with a data from a component. You might recall doing something almost exactly like this over the last few days, so reuse as much code that you've already written as you can.

  3. Open the Visual Studio .NET SDK and do a search for walkthroughs. You should get to a screen that looks something like Figure 14.16.

    Figure 14.16. Searching the SDK for walkthroughs.

    To better understand the concept of creating instances of a component with the New keyword, do the “Authoring a Component with Visual Basic .NET” or the “Authoring a Component with Visual C#” walkthrough.

    If you're interested in creating controls for Web Forms or Windows Forms applications, the component authoring walkthroughs contain many great examples and information about taking the next step in component development.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.170.223