Comments
Matt McLarty wrote: For more info... Follow me on Twitter See our website
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


DataWindow.NET How To: Data Entry Form
Simplifying database application development

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.

About 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.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

how can i change the highlight color of selected row? the default is dark blue which is too heavy. thanks

Where can I download the file frmDWMain.vb? The link to download the file is not included on the article.

Thanks


Your Feedback
alvin wrote: how can i change the highlight color of selected row? the default is dark blue which is too heavy. thanks
Allan A. Cartagenas wrote: Where can I download the file frmDWMain.vb? The link to download the file is not included on the article. Thanks
Enterprise Open Source Magazine Latest Stories . . .
New tools and services for swift software-as-a-service integration in the cloud lowers the barrier to SaaS adoption for SaaS providers and developers. MuleSoft this week launched Mule iON SaaS Edition, providing a broad set of new tools and services for swift software-as-a-Service (Sa...
All the buzz surrounding OpenStack over the past few months may beg the question of whether Openstack can repeat for Cloud what Linux has done for server operating systems over the past several years. With an enthusiastic following and a compelling, if not industry-leading set of funct...
Virtual Desktop Infrastructure (VDI) has been a hot topic in the IT community for years but delivery models have limited its use. Today there are real options for using the technology to truly replace the existing desktop infrastructure to realize tangible benefits. Today’s cloud-sourc...
VMware hypervisors of the ESX family (3.x, 4.x and 5.0) are fully, out-of-the box supported by the latest versions of OpenNebula(3.0+). If you have a server farm based on any of the ESX versions, then you can make use of OpenNebula to better manage your physical (and virtual) resources...
Data centers today are stretched to the limits with fast-paced business demands. On top of that, integrating and managing IT infrastructures can pose major challenges. Organizations need a new solution that consolidates servers and workloads without breaking the bank—and Linux, togethe...
Atlantis Computing, a provider of Virtual Desktop Infrastructure (VDI) storage and performance optimization solutions,has announced the release of Atlantis ILIO Diskless VDI 3.2, a solution that enables VMware View customers to deploy virtual desktops with no storage. Atlantis ILIO Dis...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE