Welcome!

PowerBuilder Authors: Dan Joe Barry, Carmen Gonzalez, Ian Thain, Yakov Werde, Paul Slater

Related Topics: PowerBuilder, .NET

PowerBuilder: Article

Design and Consume DataWindows in Visual Studio 2005

The power of DataWindow technology

The presentation styles supported by the DataWindow object are:

  • Grid, Tabular, Freeform
  • Crosstab, Graph, Group
  • Label, N-Up
  • Composite,Treeview
    NOTE: There is support for a TreeView Web DataWindow in DataWindow .NET 2.5

    The Data Source supported by the DataWindow object are:

  • Database Table using Quick Select, SQL Select, and Query options
  • Stored Procedures
  • Web Services
  • ADO Dataset
    NOTE: Web Services is a new feature of the DataWindow .NET 2.5. (Figure 5)

There are certain differences in DataWindow painter between the standalone DataWindow Designer of earlier versions and the DataWindow Designer plug-in hosted in Visual Studio. The plug-in has been modified to fit the Visual Studio 2005 look and feel.

What has changed in terms of look and feel?

  • DataWindow object properties are shown in the Visual Studio Properties Window.
  • The Graphic objects are shown in the Visual Studio Toolbox.
  • A new managed SQL Dialog has been added to edit data source for the DataWindow object.
  • All the DataWindow painter-related menus are integrated into the Visual Studio.
  • The way in which the DataWindow expression dialog is invoked has been changed to fit the new Properties Window.

Figure 6 highlights some of the changes mentioned above.

The discussion so far has focused on the way in which DataWindow objects can be designed directly in a Visual Studio environment using DataWindow painter. It also touched on the related modules such as the DataWindow project, Database painter, and Query painter. The next section will discuss how this created DataWindow object can be consumed in a .NET Windows and Web application.

A Typical Workflow for Creating and Consuming DataWindow Objects in Visual Studio

  1. Create a new DataWindow project in the Solution Explorer using the Visual Studio's New Project wizard.
  2. Create new pbls in the created DataWindow project using the Add New Library wizard.
  3. Configure the Database connection using the Database Painter.
  4. Create DataWindow objects inside the pbl through the Add New Entry wizard.
  5. Edit the created DataWindow object using the DataWindow Painter.
  6. Create a Windows form application. Drag-and-Drop a DataWindow control on to the form.
  7. Set the LibraryList and DataWindowObject properties of the DataWindow control. This way you can attach the object to the control.
  8. Write a few lines of C# or VB code in the Form load event to connect to a database and call the retrieve method of the DataWindow control; now you have your data with the presentation in your .NET Windows application.
  9. In order to create an ASP .NET Web Form application, drag-and-drop a WebDataWindow control on to the ASP.NET page.
  10. Import the required pbls into the bin folder of the application.
  11. Set the LibraryList and DataWindowObject properties of the WebDataWindow control.
  12. Write a few lines of C# or VB code in the Page load event to connect to a database and call the retrieve method of the WebDataWindow control and now you have your data with the presentation in your ASP.NET Web application.

Steps 1 to 5 are where you Design your DataWindow objects. Steps 6 to 12 are where you consume the DataWindow objects through a DataWindow control or a WebDataWindow control. The next section will talk about consuming DataWindow objects.

Consume DataWindows in Visual Studio
Existing DataWindow .NET users are familiar with consuming DataWindow objects in a .NET Windows or Web application. For the benefit of new users, I want to talk about how to consume DataWindow objects in Visual Studio.

What are the components distributed as part of DataWindow .NET 2.5?

  • DataWindow Control: A .NET WinForm control that can host a DataWindow object in a .NET Windows application.
  • Datastore object: A non visual container of a DataWindow object in a .NET Windows application.
  • Transaction object: An object to manage the database connection and transaction management.
  • WebDataWindow Control: An ASP.NET Web control that can host a DataWindow object in an ASP.NET Web application.

Consume a DataWindow Object in a Windows Form Application
Figure 7 says it all in one picture. Let me try to describe it for you so you can understand it better.

  • A DataWindow object called griddw1 has been created in Library1.pbl inside a DataWindow project called DWProject1.
  • Drag-and-drop the DataWindow control from the toolbox onto the Windows form named Form1.cs of the WindowsApplication1 application.
  • Set the LibraryList and DataWindow object properties of the DataWindow control to point to griddw1. This way you have attached the DataWindow object named griddw1 to the DataWindow control named datawindowControl1.
  • What C# code do we write to get the data? Very simple.
  • Connect to the database using the transaction object.
  • Associate the transaction object with the DataWindow control.
  • Call the retrieve method of the DataWindow control.

private void Form1_Load(object sender, EventArgs e)
{
this.transaction1.Dbms = Sybase.DataWindow.DbmsType.Odbc;
this.transaction1.DbParameter = "ConnectString='DSN=EAS Demo DB V110 DWD;UID=dba;PWD=sql'";
this.transaction1.Connect();
this.dataWindowControl1.SetTransaction(this.transaction1);
this.dataWindowControl1.Retrieve();
}

Consume a DataWindow Object in an ASP.NET Web Application
We can extend the same to an ASP.NET Web application by using a WebDataWindow control.

Figure 8 shows how to consume DataWindows in a Web application.

  • A DataWindow object called griddw1 has been created in Library1.pbl inside a DataWindow project called DWProject1.
  • Create a new Web application called WebSite1.
  • Import the Library1.pbl into the WebSite1.
  • Drag-and drop the WebDataWindow control from the toolbox onto the Web page Default.aspx of the WebSite1 web application.
  • Set the LibraryList and DataWindow object properties of the DataWindow control to point to griddw1. This way you have attached the DataWindow object named griddw1 to the WebDataWindow control named WebDataWindowControl1.
  • What C# code do we write to get the data? Very simple.
  • Connect to the database using the transaction object.
  • Associate the transaction object with the WebDataWindow control.
  • Call the retrieve method of the WebDataWindow control.

protected void Page_Load(object sender, EventArgs e)
{
// Profile EAS Demo DB V110 DWD
Transaction transaction1 = new Transaction();
transaction1.Dbms = Sybase.DataWindow.DbmsType.Odbc;
transaction1.AutoCommit = false;
transaction1.DbParameter = "ConnectString='DSN=EAS Demo DB
V110 DWD;UID=dba;PWD=sql'";
transaction1.Connect();
WebDataWindowControl1.SetTransaction(transaction1);
WebDataWindowControl1.Retrieve();
transaction1.Disconnect();
}

The above steps try to explain what I have been discussing in this article.

Conclusion
I hope that the message "Design and Consume DataWindows in Visual Studio 2005" has appealed to you readers in some way, to make you think about the power of the DataWindow technology in the .NET world.

Resource
•   Sybase: www.sybase.com/products/development/datawindownet.

More Stories By Geogy Zachariah

Geogy Zachariah is a senior software engineer with the PowerBuilder? DataWindow team in Sybase Singapore.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.