|By Bruce Armstrong||
|August 5, 2005 10:45 AM EDT||
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.
This month we'll look at another Microsoft sample application to see what benefits DataWindow.NET technology can provide when used for data presentation and data access in a Windows Forms (WinForms) application.
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
There are some minor differences in the header of the two forms. We're going to use ADO.NET for the DataWindow.NET version, so we won't need to import System.Data.SQLClient as the VB.NET version does. As a result, our connect string is going to be slightly different, since we'll include a data provider, as shown below. The VB.NET version also has a couple of "instance" variables.
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.
VB.NET Connect String DW.NET
Protected Const SQL_CONNECTION_STRING
As String = _
"Server=(local);" & _
"DataBase=Northwind;" & _
"Integrated Security=SSPI;Connect Timeout=5"
SQL_CONNECTION_STRING As String = _
"Data Source=(local);" & _
"Provider=SQLOLEDB;" & _
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.
|alvin 07/23/08 08:36:24 PM EDT|
how can i change the highlight color of selected row? the default is dark blue which is too heavy. thanks
|Allan A. Cartagenas 08/18/05 04:38:53 AM EDT|
Where can I download the file frmDWMain.vb? The link to download the file is not included on the article.
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- Creation and Consumption of Web Services with PowerBuilder
- Cloud People: A Who's Who of Cloud Computing
- DDDW Tips and Tricks
- Cloud Expo 2011 East To Attract 10,000 Delegates and 200 Exhibitors
- Working with SOA & Web Services in PowerBuilder
- Dynamically Creating DataWindow Objects
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form