.Net DataWindow 2.0

Doug Porter was good enough to let me know about a .Net Datawindow 2.0 Web Cast

This is interesting to me for a couple of reasons. As you know I am a fan of the DataWindow. I however have some issues with it in the .net world, because the SQL and UI layers are so tightly coupled.  I have been in touch with Sybase over the past year and they have been very responsive to the input of outsiders. One thing I have been asking for is DataSet support. Being able to use a DataSet or DataTable as the Datasource for a .Net Datawindow. Well it's coming, and version 2.0 has it. Dave Fish gave me a demonstration at PDC 05. With this feature you will be able to create a Data Access Layer and still utilize the power of the Datawindow. Once I get my hands on the Beta I will try it out report back here.

This Web Cast will cover the following new features:

  • Using .NET Datasets and Datatables as DataWindow datasources
  • Visual Studio 2005 Support
  • Dot Notation (Indexer) access to DataWindow Data
  • Hierarchical (Treeview) Style DataWindow
  • Enhanced Drop Down DataWindows for Web Apps

Connecting a .NET Datawindow to SQLServer

You may have noticed during the install of .NET DataWindow that there are no native drivers for SQL server. Sybase expects you to use OleDB to make the connection.

In case anyone is having trouble here is how to do it.

First you create the OleDBConnection object and pass that to an AdoTransaction Object. The AdoTransaction Object wraps up an ADO.Net users connection and Transaction objects so they can be used by the Datawindow.

Your code would look like this:

'Create a new OleDB Connection Object, Populate the ConnectionString Property and open the connection
Dim theConnection As New System.Data.OleDb.OleDbConnection
theConnection.ConnectionString = "Server=localhost;Provider=SQLOLEDB;Initial Catalog=Northwind;User ID=sa;Password=sa;"
theConnection.Open()

'Create a new AdoTransaction Object the constructor takes the connection object you created
Dim ADOTrans = New Sybase.DataWindow.AdoTransaction(theConnection)
'Binds the ADO.NET connection to the database interaction layer so that the AdoTransaction object can be used by a DataWindow
ADOTrans.BindConnection()

'Tell the DataWindow what Transaction Object to use
Me.DataWindowControl.SetTransaction(ADOTrans)

 

The Best of both worlds

So how is this for getting the best of both worlds.

Below you see a VB.net application using .Net Datawindows. This application took less than an hour to write. I'd like to see you write this app with PowerBuilder or VB.NET in the same time. Since all you see here on my BLOG is a screen shot, let me tell you about some of the features available in this little application.

  • There are four DataWindows. A Freeform, a Graph, labels and a Group By. They are all sharing the same disconnected record set. using a DataWindowControl method called share( ). This means if you change data in the top DW it is immediately reflected in the other Datawindows. Imagine how long creating these different views would take.
  • Thanks to VB.Net I was able to use panels, splitterbars and docking which allowed me to place these on the form and be able to shrink and grow the region they take up on the form. This was never easy in PowerBuilder.
  • Total lines of code: 5

I think the two tools together make great development partners. (I know the app is ugly that is not the point.)

Then if I change some data in the main DW and move the splitter bar over. You see the graph and Nancy's address label is different.

>

What is a DataWindow?

Since I started Blogging about the .NET DataWindow. I have had some developers ask the following questions:

  • What is so great about a DataWindow?
  • Why do you care if you can use one in your .NET application?
  • Why not just use a DataGrid?

I thought I would try and answer some of these questions for those that have never used Powerbuilder.

First you must realize there are two different objects that both get called a DataWindow. A PowerBuilder developer knows which you are talking about by the context it's used in. They are

  • DataWindow Object - Class which contains the Presentation and SQL to retrieve Data and display it to the user.
  • DataWindow Control - A Control you place on your window that takes a DataWindow Object as one of it's parameters. This object presents the DataWindow Object to the user on your form.
    • Inheritable
    • Sample Methods
      • Retrieve
      • Update
    • Sample Events
      • RowFocusChanged
      • ItemChanged

In the DataWindow editor you define a DataSource, the problem is that DataSource is part of the Datawindow Object. Sybase has to change the .NET Datawindow to take an external DataSource, like a DataSet or Business Object that implements IListSource. I may write something that hooks a DataSet to a DataWindow if I get time. Perhaps Sybase will fly me down to meet with the.NET DataWindow Architects and give them some suggestions. Hint Hint

Back to how it works. Once you have your Data Source defined you move to the presentation side of the DataWindow. Here is the good thing about having the data and presentation together in one object. There is no binding issues. You get a column for each column in the result set. So you paint your Datawindow and please realize this is not just a grid. This can be a graph, labels, grid, tabular or you can make it look just like a for with buttons, group boxes, textboxes and labels.

Once you have a completed DataWindow. You drop a DataWindow Control on your form set the DataObject Property to the name of your DataWindow Object. Then just tell the DataWindow Control what Transaction you are using and call the retrieve method.

So that is a really simple example of how it works. In my next Blog entry I'll tell you why I think they are so good. 

My .NET Datawindow works

I got some help from two very nice gentleman at Sybase who read my Blog and offered to help me get my sample application with the .NET DataWindow working. As it turned out I abandoned the project I made and created a new one and it worked. I have no answer as to why at this point.

So I made a C# windows application and a VB.NET windows application. Each with a Datawindow that gathers data from the employee table of the Northwind Database. The DataWindow I created contains a computed field, and expressions to colour certain rows and columns based on the data retrieved.

I also added a sybase transaction object and three lines of code that I have written in powerscript many many many times.

  1. this.transaction.Connect();
  2. this.dataWindowControl1.SetTransaction(this.transaction);
  3. this.dataWindowControl1.Retrieve();

So check it out. Below you see a Datawindow. With the following expressions. If the country is UK make the whole row grey. If the employee was born before 1960 show their name in red. Autosize the height of the address column. :)

DataWindow .Net

Tonight I installed DataWindow.Net, which is shipping with PowerBuilder 10. It's a set of libraries that let you use PowerBuilder DataWindows in your .Net applications.

I downloaded an evaluation version of DataWindow.Net and the Datawindow Designer. I had to see what it was like. So I installed it, the install said it couldn't find a copy of Visual Studio 2003. So I had to add the Datawindow objects to the VS toolbox myself.

It added a DatawindowControl and DataStore and a Transaction Object.

So I opened the datawindow Designer and created a datawindow. Didn't have much trouble with that, it looked pretty much like PowerBuilder. Then I created a windows application in .Net and dropped a DataWindowControl on the form set the LibraryList property and DataObject property and there was my Datawindow in my .NET form.

I added a button and coded a setTransaction and Retrieve. (DataWindowControl methods to tell the datawindow what Database to connect to and execute the Select command of the Datawindow.)

My application built without error. And the bin directory contained a PBD (PowerBuilders version of a DLL) containing my Datawindow Object, along with some other Sybase DLL's. Unfortunately when I run my little application I get a TypeLoadException “Could not load type Sybase.DataWindow.DatawindowControl“. But I'm tired anyway so I'll try again tomorrow.

I'm going to try and do some more investigation. Mostly just for my own curiosity. There are a lot of things I don't miss about the Datawindow but there are a lot of things I miss a lot.

If anyone else out there is evaluating this new Sybase effort to save the DataWindow I'd be very interested in your findings also.