PowerBuilder Tips, Tricks, and Techniques

Berndt Hamboeck

Subscribe to Berndt Hamboeck: eMailAlertsEmail Alerts
Get Berndt Hamboeck: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


PowerBuilder: Article

SQL Anywhere 10 & DataWindow .NET 2.0 in an ASP Environment

Speeding up database development

From a WebForm App to a WinForm App
BUILDING ASPX PAGES
As mentioned above, the goal was to move the services screen to the Web. As you can see below, the existing WinForm services consist of two DataWindows. The upper one is a grid view of the entered services. The lower one is the editable DataWindow -the place where users change or enter a new service.

Create a WinForm Application Using SQL Anywhere and DataWindow.NET(Fig A)
1.  Open VS2005 and create a new Web Application
2.  Create folders for PBL and images(Fig B)

  • Import PBL and images
  • Add a new Web page to the project and give it the name FormServices.aspx
Note: I have some more files in my project since I moved some of my own framework files from the WinForm application to the WebForm application (like the settings and code for the multi-language support).

The only thing I had to change was how I passed references to my DataWindows as in the WinForm application I passed Sybase.DataWindow.DataWindowControl and in the WebForm application one has to pass Sybase.DataWindow.Web.WebDataWindowControl.

3.  Add a table to the page

  • Add two DataWindows to the page
  • Add image buttons
  • Add checkboxes
  • Add a textbox for displaying error messages (Fig C)
4.  Change the name of the two DataWindows
  • Set the library
  • Set the DataWindow object
  • Enable paging for the list view (Fig D)
5.  Script Page_Load event to:
  • Connect to the DB
  • Retrieve data

protected void Page_Load(object sender, EventArgs e)
    {
      string sDataSource = ConfigurationManager.ConnectionStrings["DATASOURCE"].ConnectionString.Trim();
      oleDbConn = new System.Data.OleDb.OleDbConnection();
      oleDbConn.ConnectionString = sDataSource;

      if (!Page.IsPostBack)
      {
        try
        {
          oleDbConn.Open();
          SQLCA = new Sybase.DataWindow.AdoTransaction(oleDbConn);
          SQLCA.BindConnection();

          dw.SetTransaction(SQLCA);
          dw.Retrieve();
          dw.ShareData(dwEdit);

          //AppConfig.DWInternationalize(dw);
          //AppConfig.DWInternationalize(dwEdit);

        }
        catch (System.Data.OleDb.OleDbException ex)
        {
          lbErrorText.Text = ex.Message;
        }
        finally
        {
          oleDbConn.Close();
        }
      }
    }

6.  Add the connection to the Web.Config file

<connectionStrings>
    <add name="DATASOURCE" connectionString="Provider=SAOLEDB.10;ENG=PamalotASA10;DBN=PamalotASA10;
    LINKS=tcpip;User ID=dba;Password=sql;" providerName="System.Data.OleDb"/>
</connectionStrings>

7.  Run the application by pressing the F5 key
Your default browser opens and points to the URL: http://localhost:50552/FormServices.aspx

If everything is correct the output looks (depending on your own DataWindow objects) something like Figure 2. Note: Make sure that the SQL Anywhere database server is started before you run the web application.

Figure 1 shows the "old" WinForm application and Figure 2 shows the new WebForm application. Doesn't look that different, does it? And this was exactly the goal we wanted to reach. The behavior and the look-and-feel should be much the same as before, and all of this should be done in a very short time, which is only possible if one can take the look and framework classes nearly unchanged from one environment to the other. (Figure 3)


More Stories By Berndt Hamboeck

Berndt Hamboeck is a senior consultant for BHITCON (www.bhitcon.net). He's a CSI, SCAPC8, EASAC, SCJP2, and started his Sybase development using PB5. You can reach him under [email protected]

Comments (1)

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.