| By Bruce Armstrong | Article Rating: |
|
| August 5, 2005 10:45 AM EDT | Reads: |
28,662 |
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
Connect String
Protected Const SQL_CONNECTION_STRING
As String = _
"Server=(local);" & _
"DataBase=Northwind;" & _
"Integrated Security=SSPI;Connect Timeout=5"
Protected Const
SQL_CONNECTION_STRING As String = _
"Data Source=(local);" & _
"Provider=SQLOLEDB;" & _
"Initial Catalog=Northwind;"
& _
"Integrated Security=SSPI
;Connect Timeout=5;"
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.
Published August 5, 2005 Reads 28,662
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Bruce Armstrong
Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.
![]() |
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. Thanks |
||||
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- How PowerBuilder Got Its Groove Back
- The Cloud Has Cross-Border Ambitions
- Ulitzer Names The World's 30 Most Influential Virtualization Bloggers
- Ulitzer Named "New Media" Partner of Greatly Anticipated iStrategy Event in Berlin
- Risks and Enterprise Mobility?
- Steps for Success in Enterprise Mobility?
- Are Mobile Luddites Resisting Mobility?
- The Difference Between Web Hosting and Cloud Computing
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- Five Reasons to Choose a Private Cloud
- Seeding The Cloud: The Future of Data Management
- The Threat Behind the Firewall
- Economy Drives Adoption of Virtual Lab Technology
- Tips for Efficient PaaS Application Design
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- The Top 250 Players in the Cloud Computing Ecosystem
- Custom Common Dialogs Using SetWindowsHookEx
- DDDW Tips and Tricks
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form
- Book Excerpt: Sybase Adaptive Server Anywhere
- Sybase ASE 12.5 Performance and Tuning
- Working with SOA & Web Services in PowerBuilder
- Office 2003 Toolbar: A New Look For Your Old PowerBuilder App
- Dynamically Creating DataWindow Objects

































