|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
DataWindows DataWindow.NET How To: Data Entry Form
Simplifying database application development
By: Bruce Armstrong
Aug. 5, 2005 10:45 AM
Last month we looked at Microsoft's .NET Pet Shop sample application and saw how DataWindow.NET technology could be used in the data access layer of an ASP.NET-based application to reduce the its complexity and increase developer productivity.
To fully appreciate how much DataWindow.NET simplifies the development of database applications in Windows Forms, you'll need the Microsoft sample application as a reference point. In this case, you'll want the Visual Basic .NET Code Sample: Data Access - Data Entry Form available at www.microsoft.com/downloads/details.aspx? FamilyID=34e601ca-e4b8-43ac-bfa9-426483a392df&displaylang=en. The sample connects to the Northwinds sample database either in MS SQL Sever or MSDE so you will need to have that installed too. Once you have the Microsoft sample, add the sample code from this article to that same folder, and then add the frmDWMain.vb file to the project by right-clicking on the project, selecting "Add," and then "Add Existing Item" (as shown in Figure 1). In the subsequent dialog, select the frmDWMain.vb file. It should now appear in the list of project files (as in Figure 2). You can now switch between the form from the original sample and the new form built with DataWindow.NET technology simply by switching the Startup Object for the project from the project property page (see Figure 3). Try running the application first with the original form (see Figure 4) as the startup object and again with the DataWindow.NET form (see Figure 5) as the startup object. Compare how each form works to verify that they both have the same functionality. There are some minor differences, which we'll cover as we compare the code. But for the most part the only thing you should notice about the way they operate is the different titles on the forms and the fact that the DataWindow.NET version implements the newer XP visual style (if you're running on XP). A Closer Look at the Code The HasConnected variable tracks whether the user has connected to the database, and is used in a function that manually populates the dropdown list boxes on the form. We'll be using the DataWindow's built-in DropDownDataWindow edit style, which automatically populates those to be used, so we don't need that variable or its related function. Secondly, the VB.NET form has a Mode variable that tracks whether the user is editing a new or existing database record. Since the DataWindow also manages that for us automatically, we don't need to bother tracking the type of update.
We're not going to get into the Windows Form Designer generated code except to note that there's a lot more of it with the VB.NET implementation. This is primarily because the VB.NET implementation used a separate windows control and text label for each of the 10 columns in the result set. We're going to use two DataWindowControls, one for the product listbox and the other for all of the other data-entry controls. A DataWindowControl implementation appears as a single control in the Windows Form Designer creating one-tenth of the code in that section. The first method that gets run on either version of the form is the frmDataEntry_Load method, the one loading the form. In the VB.NET version, there are calls to a PopulateCategoryCombo and a PopulateSupplierCombo method. Each of those has roughly 75 lines of code used to populate the two dropdownlistboxes in the VB.NET form. As I indicated above, we'll be using the DropDownDataWindow edit style for those dropdowns, so the DataWindow automatically handles their population. The DW.NET version doesn't have those methods. In the DW.NET version of frmDataEntryLoad we have the assignment of the LibraryList and DataWindowObject properties of the two DataWindowControls on the form (though this could have been handled through the property editor as well). We're also doing a ShareData so that we can retrieve the product data into one of the DataWindowControls but display that same data in different layouts in both DataWindowControls. Both versions of that method then make a call to the PopulateProductList method. Note that the btnRefresh_Click method on both forms contains very similar code, at least with respect to the call to the three methods in the VB.NET version and the call to the PopulateProdcutList method only in the DW.NET version. Reader Feedback: Page 1 of 1
Your Feedback
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||